home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / pine3.92 / pine / init.c < prev    next >
C/C++ Source or Header  |  1996-03-17  |  138KB  |  4,269 lines

  1. #if !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: init.c,v 4.344 1996/03/18 19:46:26 mikes Exp $";
  3. #endif
  4. /*----------------------------------------------------------------------
  5.  
  6.             T H E    P I N E    M A I L   S Y S T E M
  7.  
  8.    Laurence Lundblade and Mike Seibel
  9.    Networks and Distributed Computing
  10.    Computing and Communications
  11.    University of Washington
  12.    Administration Builiding, AG-44
  13.    Seattle, Washington, 98195, USA
  14.    Internet: lgl@CAC.Washington.EDU
  15.              mikes@CAC.Washington.EDU
  16.  
  17.    Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  18.  
  19.  
  20.    Pine and Pico are registered trademarks of the University of Washington.
  21.    No commercial use of these trademarks may be made without prior written
  22.    permission of the University of Washington.
  23.  
  24.    Pine, Pico, and Pilot software and its included text are Copyright
  25.    1989-1996 by the University of Washington.
  26.  
  27.    The full text of our legal notices is contained in the file called
  28.    CPYRIGHT, included with this distribution.
  29.  
  30.  
  31.    Pine is in part based on The Elm Mail System:
  32.     ***********************************************************************
  33.     *  The Elm Mail System  -  Revision: 2.13                             *
  34.     *                                                                     *
  35.     *             Copyright (c) 1986, 1987 Dave Taylor              *
  36.     *             Copyright (c) 1988, 1989 USENET Community Trust   *
  37.     ***********************************************************************
  38.  
  39.  
  40.   ----------------------------------------------------------------------*/
  41.  
  42. /*======================================================================
  43.      init.c
  44.      Routines for pine start up and initialization
  45.        init_vars
  46.        free_vars
  47.        init_username
  48.        init_hostname
  49.        read_pinerc
  50.        write_pinerc
  51.        init_mail_dir
  52.  
  53.        sent-mail expiration
  54.  
  55.        open debug files 
  56.  
  57.       - open and set up the debug files
  58.       - fetch username, password, and home directory
  59.       - get host and domain name
  60.       - read and write the users .pinerc config file
  61.       - create the "mail" subdirectory
  62.       - expire old sent-mail
  63.  
  64.   ====*/
  65.  
  66.  
  67. #include "headers.h"
  68.  
  69.  
  70. typedef enum {ParseLocal, ParseGlobal, ParseFixed} ParsePinerc;
  71. typedef enum {Sapling, Seedling, Seasoned} FeatureLevel;
  72.  
  73.  
  74. /*
  75.  * Internal prototypes
  76.  */
  77. void init_error PROTO((struct pine *, char *));
  78. void read_pinerc PROTO((char *, struct variable *, ParsePinerc));
  79. int  compare_sm_files PROTO((const QSType *, const QSType *));
  80. /* AIX gives warning here 'cause it can't quite cope with enums */
  81. void process_init_cmds PROTO((struct pine *, char **));
  82. void process_feature_list PROTO((struct pine *, char **, int , int, int));
  83. int  decode_sort PROTO((struct pine *, char *));
  84.  
  85.  
  86. #if    defined(DOS_EXTRA) && !(defined(WIN32) || defined (_WINDOWS))
  87. #define    CONF_TXT_T    char __based(__segname("_CNFT"))
  88. #else
  89. #define    CONF_TXT_T    char
  90. #endif
  91.  
  92. /*------------------------------------
  93. Some definitions to keep the static "variable" array below 
  94. a bit more readable...
  95.   ----*/
  96. /* be careful changing these PINERC_COMMENTs */
  97. CONF_TXT_T cf_text_comment1[] = "# Updated by Pine(tm) ";
  98. CONF_TXT_T cf_text_comment2[] = ", copyright 1989-1996 University of Washington.\n";
  99. CONF_TXT_T cf_text_comment3[] = "#\n# Pine configuration file -- customize as needed.\n#\n# This file sets the configuration options used by Pine and PC-Pine.  If you\n# are using Pine on a Unix system, there may be a system-wide configuration\n# file which sets the defaults for these variables.  There are comments in\n# this file to explain each variable, but if you have questions about\n# specific\
  100.  settings see the section on configuration options in the Pine\n# notes.  On Unix, run pine -conf to see how system defaults have been set.\n# For variables that accept multiple values, list elements are separated\n# by commas.  A line beginning with a space or tab is considered to be a\n# continuation of the previous line.  For a variable to be unset its value\n# must be blank.  To set a variable to the empty string its value should\n# \
  101. be \"\".  You can override system defaults by setting a variable to the\n# empty string.  Switch variables are set to either \"yes\" or \"no\", and\n# default to \"no\".\n# Lines beginning with \"#\" are comments, and ignored by Pine.\n";
  102.  
  103.  
  104. CONF_TXT_T cf_text_personal_name[] =    "Over-rides your full name from Unix password file. Required for PC-Pine.";
  105.  
  106. CONF_TXT_T cf_text_user_id[] =        "Your login/e-mail user name";
  107.  
  108. CONF_TXT_T cf_text_user_domain[] =        "Sets domain part of From: and local addresses in outgoing mail.";
  109.  
  110. CONF_TXT_T cf_text_smtp_server[] =        "List of SMTP servers for sending mail. If blank: Unix Pine uses sendmail.";
  111.  
  112. CONF_TXT_T cf_text_nntp_server[] =        "NNTP server for posting news. Also sets news-collections for news reading.";
  113.  
  114. CONF_TXT_T cf_text_inbox_path[] =        "Path of (local or remote) INBOX, e.g. ={mail.somewhere.edu}inbox\n# Normal Unix default is the local INBOX (usually /usr/spool/mail/$USER).";
  115.  
  116. CONF_TXT_T cf_text_incoming_folders[] =    "List of incoming msg folders besides INBOX, e.g. ={host2}inbox, {host3}inbox\n# Syntax: optnl-label {optnl-imap-host-name}folder-path";
  117.  
  118. CONF_TXT_T cf_text_folder_collections[] =    "List of directories where saved-message folders may be. First one is\n# the default for Saves. Example: Main {host1}mail/[], Desktop mail\\[]\n# Syntax: optnl-label {optnl-imap-hostname}optnl-directory-path[]";
  119.  
  120. CONF_TXT_T cf_text_news_collections[] =    "List, only needed if nntp-server not set, or news is on a different host\n# than used for NNTP posting. Examples: News *[] or News *{host3/nntp}[]\n# Syntax: optnl-label *{news-host/protocol}[]";
  121.  
  122. CONF_TXT_T cf_text_pruned_folders[] =    "List of context and folder pairs, delimited by a space, to be offered for\n# pruning each month.  For example: {host1}mail/[] mumble";
  123.  
  124. CONF_TXT_T cf_text_default_fcc[] =        "Over-rides default path for sent-mail folder, e.g. =old-mail (using first\n# folder collection dir) or ={host2}sent-mail or =\"\" (to suppress saving).\n# Default: sent-mail (Unix) or SENTMAIL.MTX (PC) in default folder collection.";
  125.  
  126. CONF_TXT_T cf_text_default_saved[] =    "Over-rides default path for saved-msg folder, e.g. =saved-messages (using first\n# folder collection dir) or ={host2}saved-mail or =\"\" (to suppress saving).\n# Default: saved-messages (Unix) or SAVEMAIL.MTX (PC) in default folder collection.";
  127.  
  128. CONF_TXT_T cf_text_postponed_folder[] =    "Over-rides default path for postponed messages folder, e.g. =pm (which uses\n# first folder collection dir) or ={host4}pm (using home dir on host4).\n# Default: postponed-msgs (Unix) or POSTPOND.MTX (PC) in default fldr coltn.";
  129.  
  130. CONF_TXT_T cf_text_mail_directory[] =    "Pine compares this value with the first folder collection directory.\n# If they match (or no folder collections are defined), and the directory\n# does not exist, Pine will create and use it. Default: ~/mail";
  131.  
  132. CONF_TXT_T cf_text_read_message_folder[] =    "If set, specifies where already-read messages will be moved upon quitting.";
  133.  
  134. CONF_TXT_T cf_text_signature_file[] =    "Over-rides default path for signature file. Default is ~/.signature";
  135.  
  136. CONF_TXT_T cf_text_global_address_book[] =    "List of file or path names for global/shared addressbook(s).\n# Default: none\n# Syntax: optnl-label path-name";
  137.  
  138. CONF_TXT_T cf_text_address_book[] =    "List of file or path names for personal addressbook(s).\n# Default: ~/.addressbook (Unix) or \\PINE\\ADDRBOOK (PC)\n# Syntax: optnl-label path-name";
  139.  
  140. CONF_TXT_T cf_text_feature_list[] =    "List of features; see Pine's Setup/options menu for the current set.\n# e.g. feature-list= select-without-confirm, signature-at-bottom\n# Default condition for all of the features is no-.";
  141.  
  142. CONF_TXT_T cf_text_initial_keystroke_list[] =    "Pine executes these keys upon startup (e.g. to view msg 13: i,j,1,3,CR,v)";
  143.  
  144. CONF_TXT_T cf_text_default_composer_hdrs[] =    "Only show these headers (by default) when composing messages";
  145.  
  146. CONF_TXT_T cf_text_customized_hdrs[] =    "Add these customized headers (and possible default values) when composing";
  147.  
  148. CONF_TXT_T cf_text_view_headers[] =    "When viewing messages, include this list of headers";
  149.  
  150. CONF_TXT_T cf_text_save_msg_name_rule[] =    "Determines default folder name for Saves...\n# Choices: default-folder, by-sender, by-from, by-recipient, last-folder-used.\n# Default: \"default-folder\", i.e. \"saved-messages\" (Unix) or \"SAVEMAIL\" (PC).";
  151.  
  152. CONF_TXT_T cf_text_fcc_name_rule[] =    "Determines default name for Fcc...\n# Choices: default-fcc, by-recipient, last-fcc-used.\n# Default: \"default-fcc\" (see also \"default-fcc=\" variable.)";
  153.  
  154. CONF_TXT_T cf_text_sort_key[] =        "Sets presentation order of messages in Index. Choices:\n# subject, from, arrival, date, size. Default: \"arrival\".";
  155.  
  156. CONF_TXT_T cf_text_addrbook_sort_rule[] =    "Sets presentation order of address book entries. Choices: dont-sort,\n# fullname-with-lists-last, fullname, nickname-with-lists-last, nickname\n# Default: \"fullname-with-lists-last\".";
  157.  
  158. CONF_TXT_T cf_text_character_set[] =    "Reflects capabilities of the display you have. Default: US-ASCII.\n# Typical alternatives include ISO-8859-x, (x is a number between 1 and 9).";
  159.  
  160. CONF_TXT_T cf_text_editor[] =        "Specifies the program invoked by ^_ in the Composer,\n# or the \"enable-alternate-editor-implicitly\" feature.";
  161.  
  162. CONF_TXT_T cf_text_speller[] =        "Specifies the program invoked by ^T in the Composer.";
  163.  
  164. CONF_TXT_T cf_text_fillcol[] =        "Specifies the column of the screen where the composer should wrap.";
  165.  
  166. CONF_TXT_T cf_text_replystr[] =        "Specifies the string to insert when replying to  message.";
  167.  
  168. CONF_TXT_T cf_text_image_viewer[] =    "Program to view images (e.g. GIF or TIFF attachments).";
  169.  
  170. CONF_TXT_T cf_text_use_only_domain_name[] = "If \"user-domain\" not set, strips hostname in FROM address. (Unix only)";
  171.  
  172. CONF_TXT_T cf_text_printer[] =        "Your default printer selection";
  173.  
  174. CONF_TXT_T cf_text_personal_print_command[] =    "List of special print commands";
  175.  
  176. CONF_TXT_T cf_text_personal_print_cat[] =    "Which category default print command is in";
  177.  
  178. CONF_TXT_T cf_text_standard_printer[] =    "The system wide standard printers";
  179.  
  180. CONF_TXT_T cf_text_last_time_prune_quest[] =    "Set by Pine; controls beginning-of-month sent-mail pruning.";
  181.  
  182. CONF_TXT_T cf_text_last_version_used[] =    "Set by Pine; controls display of \"new version\" message.";
  183.  
  184. CONF_TXT_T cf_text_bugs_fullname[] =    "Full name for bug report address used by \"Report Bug\" command.\n# Default: Pine Developers";
  185.  
  186. CONF_TXT_T cf_text_bugs_address[] =    "Email address used to send bug reports.\n# Default: pine-bugs@cac.washington.edu";
  187.  
  188. CONF_TXT_T cf_text_bugs_extras[] =        "Program/Script used by \"Report Bug\" command. No default.";
  189.  
  190. CONF_TXT_T cf_text_suggest_fullname[] =    "Full name for suggestion address used by \"Report Bug\" command.\n# Default: Pine Developers";
  191.  
  192. CONF_TXT_T cf_text_suggest_address[] =    "Email address used to send suggestions.\n# Default: pine-suggestions@cac.washington.edu";
  193.  
  194. CONF_TXT_T cf_text_local_fullname[] =    "Full name for \"local support\" address used by \"Report Bug\" command.\n# Default: Local Support";
  195.  
  196. CONF_TXT_T cf_text_local_address[] =    "Email address used to send to \"local support\".\n# Default: postmaster";
  197.  
  198. CONF_TXT_T cf_text_forced_abook[] =    "Force these address book entries into all writable personal address books.\n# Syntax is   forced-abook-entry=nickname|fullname|address\n# This is a comma-separated list of entries, each with syntax above.\n# Existing entries with same nickname are not replaced.\n# Example: help|Help Desk|help@ourdomain.com";
  199.  
  200. CONF_TXT_T cf_text_kblock_passwd[] =    "This is a number between 1 and 5.  It is the number of times a user will\n# have to enter a password when they run the keyboard lock command in the\n# main menu.  Default is 1.";
  201.  
  202. CONF_TXT_T cf_text_sendmail_path[] =    "This names the path to an alternative sendmail program which is\n# usually \"/usr/lib/sendmail\".  It must support sendmail's \"-t\" option.";
  203.  
  204. CONF_TXT_T cf_text_oper_dir[] =    "This names the root of the tree to which the user is restricted when reading\n# and writing folders and files.  For example, on Unix ~/work confines the\n# user to the subtree beginning with their work subdirectory.\n# (Note: this alone is not sufficient for preventing access.  You will also\n# need to restrict shell access and so on, see Pine Technical Notes.)\n# Default: not set (so no restriction)";
  205.  
  206. CONF_TXT_T cf_text_in_fltr[] =         "This variable takes a list of programs that message text is piped into\n# after MIME decoding, prior to display.";
  207.  
  208. CONF_TXT_T cf_text_out_fltr[] =        "This defines a program that message text is piped into before MIME\n# encoding, prior to sending";
  209.  
  210. CONF_TXT_T cf_text_alt_addrs[] =        "A list of alternate addresses the user is known by";
  211.  
  212. CONF_TXT_T cf_text_abook_formats[] =    "This is a list of formats for address books.  Each entry in the list is made\n# up of space-delimited tokens telling which fields are displayed and in\n# which order.  See help text";
  213.  
  214. CONF_TXT_T cf_text_index_format[] =    "This gives a format for displaying the index.  It is made\n# up of space-delimited tokens telling which fields are displayed and in\n# which order.  See help text";
  215.  
  216. CONF_TXT_T cf_text_overlap[] =        "The number of lines of overlap when scrolling through message text";
  217.  
  218. CONF_TXT_T cf_text_stat_msg_delay[] =    "The number of seconds to sleep after writing a status message";
  219.  
  220. CONF_TXT_T cf_text_mailcheck[] =        "The approximate number of seconds between checks for new mail";
  221.  
  222. CONF_TXT_T cf_text_news_active[] =        "Path and filename of news configation's active file.\n# The default is typically \"/usr/lib/news/active\".";
  223.  
  224. CONF_TXT_T cf_text_news_spooldir[] =    "Directory containing system's news data.\n# The default is typically \"/usr/spool/news\"";
  225.  
  226. CONF_TXT_T cf_text_upload_cmd[] =        "Path and filename of the program used to upload text from your terminal\n# emulator's into Pine's composer.";
  227.  
  228. CONF_TXT_T cf_text_upload_prefix[] =    "Text sent to terminal emulator prior to invoking the program defined by\n# the upload-command variable.\n# Note: _FILE_ will be replaced with the temporary file used in the upload.";
  229.  
  230. CONF_TXT_T cf_text_download_cmd[] =    "Path and filename of the program used to download text via your terminal\n# emulator from Pine's export and save commands.";
  231.  
  232. CONF_TXT_T cf_text_download_prefix[] =    "Text sent to terminal emulator prior to invoking the program defined by\n# the download-command variable.\n# Note: _FILE_ will be replaced with the temporary file used in the downlaod.";
  233.  
  234. CONF_TXT_T cf_text_goto_default[] =    "Sets the default folder and collectionoffered at the Goto Command's prompt.";
  235.  
  236. CONF_TXT_T cf_text_mailcap_path[] =    "Sets the search path for the mailcap cofiguration file.\n# NOTE: colon delimited under UNIX, semi-colon delimited under DOS/Windows/OS2.";
  237.  
  238. CONF_TXT_T cf_text_mimetype_path[] =    "Sets the search path for the mimetypes cofiguration file.\n# NOTE: colon delimited under UNIX, semi-colon delimited under DOS/Windows/OS2.";
  239.  
  240. CONF_TXT_T cf_text_tcp_open_timeo[] =    "Sets the time in seconds that Pine will attempt to open a network\n# connection.  The default is 30, the minimum is 5, and the maximum is\n# system defined (typically 75).";
  241.  
  242. CONF_TXT_T cf_text_rsh_open_timeo[] =    "Sets the time in seconds that Pine will attempt to open a UNIX remote\n# shell connection.  The default is 15, min is 5, and max is unlimited.\n# Zero disables rsh altogether.";
  243.  
  244. CONF_TXT_T cf_text_archived_folders[] =    "List of folder pairs; the first indicates a folder to archive, and the\n# second indicates the folder read messages in the first should\n# be moved to.";
  245.  
  246. CONF_TXT_T cf_text_elm_style_save[] =    "Elm-style-save is obsolete, use saved-msg-name-rule";
  247.  
  248. CONF_TXT_T cf_text_header_in_reply[] =    "Header-in-reply is obsolete, use include-header-in-reply in feature-list";
  249.  
  250. CONF_TXT_T cf_text_feature_level[] =    "Feature-level is obsolete, use feature-list";
  251.  
  252. CONF_TXT_T cf_text_old_style_reply[] =    "Old-style-reply is obsolete, use signature-at-bottom in feature-list";
  253.  
  254. CONF_TXT_T cf_text_compose_mime[] =    "Compose-mime is obsolete";
  255.  
  256. CONF_TXT_T cf_text_show_all_characters[] =    "Show-all-characters is obsolete";
  257.  
  258. CONF_TXT_T cf_text_save_by_sender[] =    "Save-by-sender is obsolete, use saved-msg-name-rule";
  259.  
  260. CONF_TXT_T cf_text_nntp_new_group_time[] =    "Last time NNTP server was checked for newly created news groups";
  261.  
  262. CONF_TXT_T cf_text_folder_extension[] =    "Extension used for local folder names (\".MTX\" by default).";
  263.  
  264. CONF_TXT_T cf_text_normal_foreground_color[] =    "Choose: black,blue,green,cyan,red,magenta,yellow,or white (CAPS=BLINKING).";
  265.  
  266. CONF_TXT_T cf_text_window_position[] =    "Window position in the format: CxR+X+Y\n# Where C and R are the window size in characters and X and Y are the\n# screen position of the top left corner of the window.";
  267.  
  268. CONF_TXT_T cf_text_newsrc_path[] =        "Full path and name of NEWSRC file";
  269.  
  270. /* these sort of divide up the pinerc file into categories */
  271. char    cf_before_personal_name[] =    "########################### Essential Parameters ###########################";
  272. char    cf_before_incoming_folders[] =    "###################### Collections, Folders, and Files #####################";
  273. char    cf_before_feature_list[] =    "############################### Preferences ################################";
  274. char    cf_before_printer[] =    "########## Set within or by Pine: No need to edit below this line ##########";
  275.  
  276.  
  277. static int    copyright_line_is_there,
  278.         trademark_lines_are_there;
  279.  
  280.  
  281. /*----------------------------------------------------------------------
  282. These are the variables that control a number of pine functions.  They
  283. come out of the .pinerc and the /usr/local/lib/pine.conf files.  Some can
  284. be set by the user while in Pine.  Eventually all the local ones should
  285. be so and maybe the global ones too.
  286.  
  287. Each variable can have a command-line, user, global, and current value.
  288. All of these values are malloc'd.  The user value is the one read out of
  289. the user's .pinerc, the global value is the one from the system pine
  290. configuration file.  There are often defaults for the global values, set
  291. at the start of init_vars().  Perhaps someday there will be group values.
  292. The current value is the one that is actually in use.
  293.   ----*/
  294. /* name::is_obsolete::is_used::been_written::is_user::is_global::is_list::
  295.    is_fixed::description */
  296. static struct variable variables[] = {
  297. {"personal-name",              0, 1, 0, 1, 1, 0, 0, cf_text_personal_name},
  298. #if defined(DOS) || defined(OS2)
  299.                         /* Have to have this on DOS, PC's, Macs, etc... */
  300. {"user-id",                    0, 1, 0, 1, 0, 0, 0,
  301. #else            /* Don't allow on UNIX machines for some security */
  302. {"user-id",                    0, 0, 0, 1, 0, 0, 0,
  303. #endif
  304.     cf_text_user_id},
  305. {"user-domain",                0, 1, 0, 1, 1, 0, 0, cf_text_user_domain},
  306. {"smtp-server",                0, 1, 0, 1, 1, 1, 0, cf_text_smtp_server},
  307. {"nntp-server",                0, 1, 0, 1, 1, 1, 0, cf_text_nntp_server},
  308. {"inbox-path",                 0, 1, 0, 1, 1, 0, 0, cf_text_inbox_path},
  309. {"incoming-folders",           0, 1, 0, 1, 1, 1, 0, cf_text_incoming_folders},
  310. {"folder-collections",         0, 1, 0, 1, 1, 1, 0,
  311.                            cf_text_folder_collections},
  312. {"news-collections",           0, 1, 0, 1, 1, 1, 0, cf_text_news_collections},
  313. {"incoming-archive-folders",   0, 1, 0, 1, 1, 1, 0, cf_text_archived_folders},
  314. {"pruned-folders",           0, 1, 0, 1, 1, 1, 0, cf_text_pruned_folders},
  315. {"default-fcc",                0, 1, 0, 1, 1, 0, 0, cf_text_default_fcc},
  316. {"default-saved-msg-folder",   0, 1, 0, 1, 1, 0, 0, cf_text_default_saved},
  317. {"postponed-folder",           0, 1, 0, 1, 1, 0, 0, cf_text_postponed_folder},
  318. {"mail-directory",             0, 1, 0, 0, 1, 0, 0, cf_text_mail_directory},
  319. {"read-message-folder",        0, 1, 0, 1, 1, 0, 0,
  320.                           cf_text_read_message_folder},
  321. {"signature-file",             0, 1, 0, 1, 1, 0, 0, cf_text_signature_file},
  322. {"global-address-book",        0, 1, 0, 1, 1, 1, 0,
  323.                           cf_text_global_address_book},
  324. {"address-book",               0, 1, 0, 1, 1, 1, 0, cf_text_address_book},
  325. {"feature-list",               0, 1, 0, 1, 1, 1, 0, cf_text_feature_list},
  326. {"initial-keystroke-list",     0, 1, 0, 1, 1, 1, 0,
  327.                            cf_text_initial_keystroke_list},
  328. {"default-composer-hdrs",      0, 1, 0, 1, 1, 1, 0,
  329.                             cf_text_default_composer_hdrs},
  330. {"customized-hdrs",            0, 1, 0, 1, 1, 1, 0, cf_text_customized_hdrs},
  331. {"viewer-hdrs",                0, 1, 0, 1, 1, 1, 0, cf_text_view_headers},
  332. {"saved-msg-name-rule",        0, 1, 0, 1, 1, 0, 0,
  333.                            cf_text_save_msg_name_rule},
  334. {"fcc-name-rule",              0, 1, 0, 1, 1, 0, 0, cf_text_fcc_name_rule},
  335. {"sort-key",                   0, 1, 0, 1, 1, 0, 0, cf_text_sort_key},
  336. {"addrbook-sort-rule",         0, 1, 0, 1, 1, 0, 0,
  337.                            cf_text_addrbook_sort_rule},
  338. {"goto-default-rule",           0, 1, 0, 1, 1, 0, 0, cf_text_goto_default},
  339. {"character-set",              0, 1, 0, 1, 1, 0, 0, cf_text_character_set},
  340. {"editor",                     0, 1, 0, 1, 1, 0, 0, cf_text_editor},
  341. {"speller",                    0, 1, 0, 1, 1, 0, 0, cf_text_speller},
  342. {"composer-wrap-column",       0, 1, 0, 1, 1, 0, 0, cf_text_fillcol},
  343. {"reply-indent-string",        0, 1, 0, 1, 1, 0, 0, cf_text_replystr},
  344. {"image-viewer",               0, 1, 0, 1, 1, 0, 0, cf_text_image_viewer},
  345. {"use-only-domain-name",       0, 1, 0, 1, 1, 0, 0,
  346.                          cf_text_use_only_domain_name},
  347. {"printer",                    0, 1, 0, 1, 1, 0, 0, cf_text_printer},
  348. {"personal-print-command",     0, 1, 0, 1, 1, 1, 0,
  349.                            cf_text_personal_print_command},
  350. {"personal-print-category",    0, 1, 0, 1, 0, 0, 0,
  351.                            cf_text_personal_print_cat},
  352. {"standard-printer",           0, 1, 0, 0, 1, 1, 0, cf_text_standard_printer},
  353. {"last-time-prune-questioned" ,0, 1, 0, 1, 0, 0, 0,
  354.                        cf_text_last_time_prune_quest},
  355. {"last-version-used",          0, 1, 0, 1, 0, 0, 0, cf_text_last_version_used},
  356. {"bugs-fullname",              0, 1, 0, 0, 1, 0, 0, cf_text_bugs_fullname},
  357. {"bugs-address",               0, 1, 0, 0, 1, 0, 0, cf_text_bugs_address},
  358. {"bugs-additional-data",       0, 1, 0, 0, 1, 0, 0, cf_text_bugs_extras},
  359. {"suggest-fullname",           0, 1, 0, 0, 1, 0, 0, cf_text_suggest_fullname},
  360. {"suggest-address",            0, 1, 0, 0, 1, 0, 0, cf_text_suggest_address},
  361. {"local-fullname",             0, 1, 0, 0, 1, 0, 0, cf_text_local_fullname},
  362. {"local-address",              0, 1, 0, 0, 1, 0, 0, cf_text_local_address},
  363. {"forced-abook-entry",         0, 1, 0, 0, 1, 1, 0, cf_text_forced_abook},
  364. {"kblock-passwd-count",        0, 1, 0, 0, 1, 0, 0, cf_text_kblock_passwd},
  365. {"sendmail-path",           0, 1, 0, 1, 1, 0, 0, cf_text_sendmail_path},
  366. {"operating-dir",           0, 1, 0, 1, 1, 0, 0, cf_text_oper_dir},
  367. {"display-filters",           0, 1, 0, 1, 1, 1, 0, cf_text_in_fltr},
  368. {"sending-filters",           0, 1, 0, 1, 1, 1, 0, cf_text_out_fltr},
  369. {"alt-addresses",              0, 1, 0, 1, 1, 1, 0, cf_text_alt_addrs},
  370. {"addressbook-formats",        0, 1, 0, 1, 1, 1, 0, cf_text_abook_formats},
  371. {"index-format",               0, 1, 0, 1, 1, 0, 0, cf_text_index_format},
  372. {"viewer-overlap",             0, 1, 0, 1, 1, 0, 0, cf_text_overlap},
  373. {"status-message-delay",       0, 1, 0, 1, 1, 0, 0, cf_text_stat_msg_delay},
  374. {"mail-check-interval",        0, 1, 0, 1, 1, 0, 0, cf_text_mailcheck},
  375. {"newsrc-path",               0, 1, 0, 1, 1, 0, 0, cf_text_newsrc_path},
  376. {"news-active-file-path",      0, 1, 0, 1, 1, 0, 0, cf_text_news_active},
  377. {"news-spool-directory",       0, 1, 0, 1, 1, 0, 0, cf_text_news_spooldir},
  378. {"upload-command",           0, 1, 0, 1, 1, 0, 0, cf_text_upload_cmd},
  379. {"upload-command-prefix",      0, 1, 0, 1, 1, 0, 0, cf_text_upload_prefix},
  380. {"download-command",           0, 1, 0, 1, 1, 0, 0, cf_text_download_cmd},
  381. {"download-command-prefix",    0, 1, 0, 1, 1, 0, 0, cf_text_download_prefix},
  382. {"mailcap-search-path",           0, 1, 0, 1, 1, 0, 0, cf_text_mailcap_path},
  383. {"mimetype-search-path",       0, 1, 0, 1, 1, 0, 0, cf_text_mimetype_path},
  384. {"tcp-open-timeout",           0, 1, 0, 1, 1, 0, 0, cf_text_tcp_open_timeo},
  385. {"rsh-open-timeout",           0, 1, 0, 1, 1, 0, 0, cf_text_rsh_open_timeo},
  386.  
  387. #ifdef NEWBB
  388. {"nntp-new-group-time",        0, 1, 0, 1, 0, 0, 0,
  389.                           cf_text_nntp_new_group_time},
  390. #endif
  391. /* OBSOLETE VARS */
  392. {"elm-style-save",             1, 1, 0, 1, 1, 0, 0, cf_text_elm_style_save},
  393. {"header-in-reply",            1, 1, 0, 1, 1, 0, 0, cf_text_header_in_reply},
  394. {"feature-level",              1, 1, 0, 1, 1, 0, 0, cf_text_feature_level},
  395. {"old-style-reply",            1, 1, 0, 1, 1, 0, 0, cf_text_old_style_reply},
  396. {"compose-mime",               1, 1, 0, 0, 1, 0, 0, cf_text_compose_mime},
  397. {"show-all-characters",        1, 1, 0, 1, 1, 0, 0,
  398.                           cf_text_show_all_characters},
  399. {"save-by-sender",             1, 1, 0, 1, 1, 0, 0, cf_text_save_by_sender},
  400. #if defined(DOS) || defined(OS2)
  401. {"folder-extension",           0, 1, 0, 1, 1, 0, 0, cf_text_folder_extension},
  402. {"normal-foreground-color",    0, 1, 0, 1, 1, 0, 0,
  403.                         cf_text_normal_foreground_color},
  404. {"normal-background-color",    0, 1, 0, 1, 1, 0, 0, NULL},
  405. {"reverse-foreground-color",   0, 1, 0, 1, 1, 0, 0, NULL},
  406. {"reverse-background-color",   0, 1, 0, 1, 1, 0, 0, NULL},
  407. #ifdef _WINDOWS
  408. {"font-name",                  0, 1, 0, 1, 1, 0, 0, "Name and size of font."},
  409. {"font-size",                  0, 1, 0, 1, 1, 0, 0, NULL},
  410. {"font-style",                 0, 1, 0, 1, 1, 0, 0, NULL},
  411. {"print-font-name",            0, 1, 0, 1, 1, 0, 0,
  412.                          "Name and size of printer font."},
  413. {"print-font-size",            0, 1, 0, 1, 1, 0, 0, NULL},
  414. {"print-font-style",           0, 1, 0, 1, 1, 0, 0, NULL},
  415. {"window-position",            0, 1, 0, 1, 1, 0, 0, cf_text_window_position},
  416. #endif    /* _WINDOWS */
  417. #endif    /* DOS */
  418. {NULL,                         0, 0, 0, 0, 0, 0, 0, NULL},
  419. };
  420.  
  421.  
  422. #if defined(DOS) || defined(OS2)
  423. /*
  424.  * Table containing Code Page value to external charset value mappings
  425.  */
  426. unsigned char *xlate_to_codepage   = NULL;
  427. unsigned char *xlate_from_codepage = NULL;
  428. #endif
  429.  
  430.  
  431. static struct pinerc_line {
  432.   char *line;
  433.   struct variable *var;
  434.   unsigned int  is_var:1;
  435.   unsigned int  is_quoted:1;
  436.   unsigned int  obsolete_var:1;
  437. } *pinerc_lines = NULL;
  438.  
  439.  
  440. #ifdef    DEBUG
  441. /*
  442.  * Debug level and output file defined here, referenced globally.
  443.  * The debug file is opened and initialized below...
  444.  */
  445. int   debug    = DEFAULT_DEBUG;
  446. FILE *debugfile = NULL;
  447. #endif
  448.  
  449.  
  450. init_init_vars(ps)
  451.      struct pine *ps;
  452. {
  453.     ps->vars = variables;
  454. }
  455.  
  456.     
  457. /*----------------------------------------------------------------------
  458.      Initialize the variables
  459.  
  460.  Args:   ps   -- The usual pine structure
  461.  
  462.  Result: 
  463.  
  464.   This reads the system pine configuration file and the user's pine
  465. configuration file ".pinerc" and places the results in the variables 
  466. structure.  It sorts out what was read and sets a few other variables 
  467. based on the contents.
  468.   ----*/
  469. void 
  470. init_vars(ps)
  471.      struct pine *ps;
  472. {
  473.     char     buf[MAXPATH +1], *p, *q, **s;
  474.     register struct variable *vars = ps->vars;
  475.     int         obs_header_in_reply,     /* the obs_ variables are to       */
  476.          obs_old_style_reply,     /* support backwards compatibility */
  477.          obs_save_by_sender, i;
  478.     FeatureLevel obs_feature_level;
  479.  
  480.     /*--- The defaults here are defined in os-xxx.h so they can vary
  481.           per machine ---*/
  482.  
  483.     GLO_PRINTER            = cpystr(DF_DEFAULT_PRINTER);
  484.     GLO_ELM_STYLE_SAVE        = cpystr(DF_ELM_STYLE_SAVE);
  485.     GLO_SAVE_BY_SENDER        = cpystr(DF_SAVE_BY_SENDER);
  486.     GLO_HEADER_IN_REPLY        = cpystr(DF_HEADER_IN_REPLY);
  487.     GLO_INBOX_PATH        = cpystr("inbox");
  488.     GLO_DEFAULT_FCC        = cpystr(DF_DEFAULT_FCC);
  489.     GLO_DEFAULT_SAVE_FOLDER    = cpystr(DEFAULT_SAVE);
  490.     GLO_POSTPONED_FOLDER    = cpystr(POSTPONED_MSGS);
  491.     GLO_USE_ONLY_DOMAIN_NAME    = cpystr(DF_USE_ONLY_DOMAIN_NAME);
  492.     GLO_FEATURE_LEVEL        = cpystr(DF_FEATURE_LEVEL);
  493.     GLO_OLD_STYLE_REPLY        = cpystr(DF_OLD_STYLE_REPLY);
  494.     GLO_SORT_KEY        = cpystr(DF_SORT_KEY);
  495.     GLO_SAVED_MSG_NAME_RULE    = cpystr(DF_SAVED_MSG_NAME_RULE);
  496.     GLO_FCC_RULE        = cpystr(DF_FCC_RULE);
  497.     GLO_AB_SORT_RULE        = cpystr(DF_AB_SORT_RULE);
  498.     GLO_SIGNATURE_FILE        = cpystr(DF_SIGNATURE_FILE);
  499.     GLO_MAIL_DIRECTORY        = cpystr(DF_MAIL_DIRECTORY);
  500.     GLO_BUGS_FULLNAME        = cpystr(DF_BUGS_FULLNAME);
  501.     GLO_BUGS_ADDRESS        = cpystr(DF_BUGS_ADDRESS);
  502.     GLO_SUGGEST_FULLNAME    = cpystr(DF_SUGGEST_FULLNAME);
  503.     GLO_SUGGEST_ADDRESS        = cpystr(DF_SUGGEST_ADDRESS);
  504.     GLO_LOCAL_FULLNAME        = cpystr(DF_LOCAL_FULLNAME);
  505.     GLO_LOCAL_ADDRESS        = cpystr(DF_LOCAL_ADDRESS);
  506.     GLO_OVERLAP            = cpystr(DF_OVERLAP);
  507.     GLO_FILLCOL            = cpystr(DF_FILLCOL);
  508.     GLO_REPLY_STRING        = cpystr("> ");
  509.     GLO_STATUS_MSG_DELAY    = cpystr("0");
  510.     GLO_MAILCHECK        = cpystr(DF_MAILCHECK);
  511.     GLO_KBLOCK_PASSWD_COUNT    = cpystr(DF_KBLOCK_PASSWD_COUNT);
  512. #ifdef    DF_FOLDER_EXTENSION
  513.     GLO_FOLDER_EXTENSION    = cpystr(DF_FOLDER_EXTENSION);
  514. #endif
  515.  
  516.     /*
  517.      * Default first value for addrbook list if none set.
  518.      * We also want to be sure to set global_val to the default
  519.      * if is_fixed, so that address-book= will cause the default to happen.
  520.      */
  521.     if(!GLO_ADDRESSBOOK && !FIX_ADDRESSBOOK)
  522.       GLO_ADDRESSBOOK = parse_list(DF_ADDRESSBOOK, 1, NULL);
  523.  
  524.     /*
  525.      * Default first value if none set.
  526.      */
  527.     if(!GLO_STANDARD_PRINTER && !FIX_STANDARD_PRINTER)
  528.       GLO_STANDARD_PRINTER = parse_list(DF_STANDARD_PRINTER, 1, NULL);
  529.  
  530. #if defined(DOS) || defined(OS2)
  531.     /*
  532.      * Rules for the config/support file locations under DOS are:
  533.      *
  534.      * 1) The location of the PINERC is searched for in the following
  535.      *    order of precedence:
  536.      *         - File pointed to by '-p' command line option
  537.      *       - File pointed to by PINERC environment variable
  538.      *       - $HOME\pine
  539.      *       - same dir as argv[0]
  540.      *
  541.      * 2) The HOME environment variable, if not set, defaults to 
  542.      *    root of the current working drive (see pine.c)
  543.      * 
  544.      * 3) The default for external files (PINE.SIG and ADDRBOOK) is the
  545.      *    same directory as the pinerc
  546.      *
  547.      * 4) The support files (PINE.HLP and PINE.NDX) are expected to be in
  548.      *    the same directory as PINE.EXE.
  549.      */
  550.     if(!ps_global->pinerc){
  551.     if(!(p = getenv("PINERC"))){
  552.         char buf2[MAXPATH];
  553.  
  554.         p = buf;        /* ultimately holds the answer */
  555.         build_path(buf2, ps_global->home_dir, DF_PINEDIR);
  556.         if(is_writable_dir(buf2) == 0){
  557.         /* $HOME/PINE/ exists!, see if $HOME/PINE/PINERC does too */
  558.         build_path(buf, buf2, SYSTEM_PINERC);
  559.         if(can_access(buf, ACCESS_EXISTS) != 0){
  560.             /*
  561.              * no $HOME/PINE/PINERC, make sure
  562.              * one isn't already in same dir as PINE.EXE
  563.              */
  564.             build_path(buf2, ps_global->pine_dir, SYSTEM_PINERC);
  565.             if(can_access(buf, ACCESS_EXISTS) == 0)
  566.               strcpy(buf, buf2);
  567.             /* else just create $HOME/PINEDIR/PINERC */
  568.         }
  569.         /* else just create $HOME/PINEDIR/PINERC */
  570.         }
  571.         else
  572.           /* no $HOME/pine dir, put PINERC next to PINE.EXE */
  573.           build_path(buf, ps_global->pine_dir, SYSTEM_PINERC);
  574.     }
  575.  
  576.     ps_global->pinerc = cpystr(p);
  577.     }
  578.  
  579.     /*
  580.      * Now that we know the default for the PINERC, build NEWSRC default.
  581.      * Backward compatibility makes this kind of funky.  If what the
  582.      * c-client thinks the NEWSRC should be exists *AND* it doesn't
  583.      * already exist in the PINERC's dir, use c-client's default, otherwise
  584.      * use the one next to the PINERC...
  585.      */
  586.     p = last_cmpnt(ps_global->pinerc);
  587.     buf[0] = '\0';
  588.     if(p != NULL){
  589.     strncpy(buf, ps_global->pinerc, p - ps_global->pinerc);
  590.     buf[p - ps_global->pinerc] = '\0';
  591.     }
  592.  
  593.     strcat(buf, "NEWSRC");
  594.  
  595.     if(!(p = (void *) mail_parameters(NULL, GET_NEWSRC, (void *)NULL))
  596.        || can_access(p, ACCESS_EXISTS) < 0
  597.        || can_access(buf, ACCESS_EXISTS) == 0){
  598.     mail_parameters(NULL, SET_NEWSRC, (void *)buf);
  599.     GLO_NEWSRC_PATH = cpystr(buf);
  600.     }
  601.     else
  602.       GLO_NEWSRC_PATH = cpystr(p);
  603.  
  604.     /*
  605.      * Now that we know where to look for the pinerc, see if a 
  606.      * pointer to the global pine.conf has been set.  If so,
  607.      * try loading it...
  608.      */
  609.     if(!ps_global->pine_conf && (p = getenv("PINECONF")))
  610.       ps_global->pine_conf = cpystr(p);
  611.  
  612.     if(ps_global->pine_conf)
  613.       read_pinerc(ps_global->pine_conf, vars, ParseGlobal);
  614.  
  615.     read_pinerc(ps_global->pinerc, vars, ParseLocal);
  616. #else
  617.     read_pinerc(ps_global->pine_conf ? ps_global->pine_conf
  618.                      : SYSTEM_PINERC,
  619.         vars,
  620.         ParseGlobal);
  621.  
  622.     if(!ps_global->pinerc){
  623.       build_path(buf, ps->home_dir, ".pinerc");
  624.       ps_global->pinerc = cpystr(buf);
  625.     }
  626.  
  627.     read_pinerc(ps_global->pinerc, vars, ParseLocal);
  628.     read_pinerc(SYSTEM_PINERC_FIXED, vars, ParseFixed);
  629. #endif
  630.  
  631.     set_current_val(&vars[V_INBOX_PATH], TRUE, TRUE);
  632.  
  633.     set_current_val(&vars[V_USER_DOMAIN], TRUE, TRUE);
  634.     if(VAR_USER_DOMAIN
  635.        && VAR_USER_DOMAIN[0]
  636.        && (p = strrindex(VAR_USER_DOMAIN, '@'))){
  637.     if(*(++p)){
  638.         char *q;
  639.  
  640.         sprintf(tmp_20k_buf,
  641.             "User-domain (%s) cannot contain \"@\", using \"%s\"",
  642.             VAR_USER_DOMAIN, p);
  643.         init_error(ps, tmp_20k_buf);
  644.         q = VAR_USER_DOMAIN;
  645.         while((*q++ = *p++) != '\0')
  646.           ;/* do nothing */
  647.     }
  648.     else{
  649.         sprintf(tmp_20k_buf,
  650.             "User-domain (%s) cannot contain \"@\", deleting",
  651.             VAR_USER_DOMAIN);
  652.         init_error(ps, tmp_20k_buf);
  653.         fs_give((void **)&USR_USER_DOMAIN);
  654.         set_current_val(&vars[V_USER_DOMAIN], TRUE, TRUE);
  655.     }
  656.     }
  657.  
  658.     set_current_val(&vars[V_USE_ONLY_DOMAIN_NAME], TRUE, TRUE);
  659.     set_current_val(&vars[V_REPLY_STRING], TRUE, TRUE);
  660.  
  661.     /* obsolete, backwards compatibility */
  662.     set_current_val(&vars[V_HEADER_IN_REPLY], TRUE, TRUE);
  663.     obs_header_in_reply=!strucmp(VAR_HEADER_IN_REPLY, "yes");
  664.  
  665.     set_current_val(&vars[V_PRINTER], TRUE, TRUE);
  666.     set_current_val(&vars[V_PERSONAL_PRINT_COMMAND], TRUE, TRUE);
  667.     set_current_val(&vars[V_STANDARD_PRINTER], TRUE, TRUE);
  668.  
  669.     set_current_val(&vars[V_LAST_TIME_PRUNE_QUESTION], TRUE, TRUE);
  670.     if(VAR_LAST_TIME_PRUNE_QUESTION != NULL){
  671.         /* The month value in the file runs from 1-12, the variable here
  672.            runs from 0-11; the value in the file used to be 0-11, but we're 
  673.            fixing it in January */
  674.         ps->last_expire_year  = atoi(VAR_LAST_TIME_PRUNE_QUESTION);
  675.         ps->last_expire_month =
  676.             atoi(strindex(VAR_LAST_TIME_PRUNE_QUESTION, '.') + 1);
  677.         if(ps->last_expire_month == 0){
  678.             /* Fix for 0 because of old bug */
  679.             char buf[10];
  680.             sprintf(buf, "%d.%d", ps_global->last_expire_year,
  681.               ps_global->last_expire_month + 1);
  682.             set_variable(V_LAST_TIME_PRUNE_QUESTION, buf, 1);
  683.         }else{
  684.             ps->last_expire_month--; 
  685.         } 
  686.     }else{
  687.         ps->last_expire_year  = -1;
  688.         ps->last_expire_month = -1;
  689.     }
  690.  
  691.     set_current_val(&vars[V_BUGS_FULLNAME], TRUE, TRUE);
  692.     set_current_val(&vars[V_BUGS_ADDRESS], TRUE, TRUE);
  693.     set_current_val(&vars[V_SUGGEST_FULLNAME], TRUE, TRUE);
  694.     set_current_val(&vars[V_SUGGEST_ADDRESS], TRUE, TRUE);
  695.     set_current_val(&vars[V_LOCAL_FULLNAME], TRUE, TRUE);
  696.     set_current_val(&vars[V_LOCAL_ADDRESS], TRUE, TRUE);
  697.     set_current_val(&vars[V_BUGS_EXTRAS], TRUE, TRUE);
  698.     set_current_val(&vars[V_KBLOCK_PASSWD_COUNT], TRUE, TRUE);
  699.     set_current_val(&vars[V_DEFAULT_FCC], TRUE, TRUE);
  700.     set_current_val(&vars[V_POSTPONED_FOLDER], TRUE, TRUE);
  701.     set_current_val(&vars[V_READ_MESSAGE_FOLDER], TRUE, TRUE);
  702.     set_current_val(&vars[V_EDITOR], TRUE, TRUE);
  703.     set_current_val(&vars[V_SPELLER], TRUE, TRUE);
  704.     set_current_val(&vars[V_IMAGE_VIEWER], TRUE, TRUE);
  705.     set_current_val(&vars[V_SMTP_SERVER], TRUE, TRUE);
  706.     set_current_val(&vars[V_COMP_HDRS], TRUE, TRUE);
  707.     set_current_val(&vars[V_CUSTOM_HDRS], TRUE, TRUE);
  708.     set_current_val(&vars[V_SENDMAIL_PATH], TRUE, TRUE);
  709.     set_current_val(&vars[V_DISPLAY_FILTERS], TRUE, TRUE);
  710.     set_current_val(&vars[V_SEND_FILTER], TRUE, TRUE);
  711.     set_current_val(&vars[V_ALT_ADDRS], TRUE, TRUE);
  712.     set_current_val(&vars[V_ABOOK_FORMATS], TRUE, TRUE);
  713.  
  714.     set_current_val(&vars[V_OPER_DIR], TRUE, TRUE);
  715.     if(VAR_OPER_DIR && !VAR_OPER_DIR[0]){
  716.     init_error(ps,
  717.  "Setting operating-dir to the empty string is not allowed.  Will be ignored!");
  718.     fs_give((void **)&VAR_OPER_DIR);
  719.     if(FIX_OPER_DIR)
  720.       fs_give((void **)&FIX_OPER_DIR);
  721.     if(GLO_OPER_DIR)
  722.       fs_give((void **)&GLO_OPER_DIR);
  723.     if(COM_OPER_DIR)
  724.       fs_give((void **)&COM_OPER_DIR);
  725.     if(USR_OPER_DIR)
  726.       fs_give((void **)&USR_OPER_DIR);
  727.     }
  728.  
  729.     set_current_val(&vars[V_INDEX_FORMAT], TRUE, TRUE);
  730.     init_index_format(VAR_INDEX_FORMAT, &ps->index_disp_format);
  731.  
  732.     set_current_val(&vars[V_PERSONAL_PRINT_CATEGORY], TRUE, TRUE);
  733.     ps->printer_category = -1;
  734.     if(VAR_PERSONAL_PRINT_CATEGORY != NULL){
  735.     ps->printer_category = atoi(VAR_PERSONAL_PRINT_CATEGORY);
  736.     if(ps->printer_category < 1 || ps->printer_category > 3){
  737.         char **tt;
  738.         char aname[100];
  739.  
  740.         strcat(strcpy(aname, ANSI_PRINTER), "-no-formfeed");
  741.         if(strucmp(VAR_PRINTER, ANSI_PRINTER) == 0
  742.           || strucmp(VAR_PRINTER, aname) == 0)
  743.           ps->printer_category = 1;
  744.         else if(VAR_STANDARD_PRINTER && VAR_STANDARD_PRINTER[0]){
  745.         for(tt = VAR_STANDARD_PRINTER; *tt; tt++)
  746.           if(strucmp(VAR_PRINTER, *tt) == 0)
  747.             break;
  748.         
  749.         if(*tt)
  750.           ps->printer_category = 2;
  751.         }
  752.  
  753.         /* didn't find it yet */
  754.         if(ps->printer_category < 1 || ps->printer_category > 3){
  755.         if(VAR_PERSONAL_PRINT_COMMAND && VAR_PERSONAL_PRINT_COMMAND[0]){
  756.             for(tt = VAR_PERSONAL_PRINT_COMMAND; *tt; tt++)
  757.               if(strucmp(VAR_PRINTER, *tt) == 0)
  758.             break;
  759.             
  760.             if(*tt)
  761.               ps->printer_category = 3;
  762.         }
  763.         }
  764.     }
  765.     }
  766.  
  767.     set_current_val(&vars[V_OVERLAP], TRUE, TRUE);
  768.     ps->viewer_overlap = -1;
  769.     ps->viewer_overlap = atoi(VAR_OVERLAP);
  770.     if(ps->viewer_overlap < 0 || ps->viewer_overlap > 20){
  771.     sprintf(tmp_20k_buf,
  772.         "Viewer-overlap of \"%s\" not supported.  Using %s.",
  773.         VAR_OVERLAP, DF_OVERLAP);
  774.     init_error(ps, tmp_20k_buf);
  775.     ps->viewer_overlap = atoi(DF_OVERLAP);
  776.     }
  777.  
  778.     set_current_val(&vars[V_FILLCOL], TRUE, TRUE);
  779.     ps->composer_fillcol = -1;
  780.     ps->composer_fillcol = atoi(VAR_FILLCOL);
  781.     if(ps->composer_fillcol < 0 || ps->composer_fillcol > MAX_FILLCOL){
  782.     sprintf(tmp_20k_buf,
  783.         "Composer-wrap-column \"%s\" not supported%s%s%s%s. Using %s",
  784.         VAR_FILLCOL,
  785.         (ps->composer_fillcol > MAX_FILLCOL) ? " (" : "",
  786.         (ps->composer_fillcol > MAX_FILLCOL) ? "Max " : "",
  787.         (ps->composer_fillcol > MAX_FILLCOL)
  788.           ? comatose((long)MAX_FILLCOL) : "",
  789.         (ps->composer_fillcol > MAX_FILLCOL) ? ")" : "",
  790.         DF_FILLCOL);
  791.  
  792.     init_error(ps, tmp_20k_buf);
  793.     ps->composer_fillcol = atoi(DF_FILLCOL);
  794.     }
  795.     
  796.     set_current_val(&vars[V_STATUS_MSG_DELAY], TRUE, TRUE);
  797.     ps->status_msg_delay = -1;
  798.     ps->status_msg_delay = atoi(VAR_STATUS_MSG_DELAY);
  799.     if(ps->status_msg_delay < 0 || ps->status_msg_delay > 30){
  800.     sprintf(tmp_20k_buf,
  801.         "Status-message-delay \"%s\" not supported.  Using 0.",
  802.         VAR_STATUS_MSG_DELAY);
  803.     init_error(ps, tmp_20k_buf);
  804.     ps->status_msg_delay = 0;
  805.     }
  806.  
  807.     /* timeout is a regular extern int because it is referenced in pico */
  808.     set_current_val(&vars[V_MAILCHECK], TRUE, TRUE);
  809.     timeout = -1;
  810.     timeout = atoi(VAR_MAILCHECK);
  811.     if(timeout < 15 && timeout != 0){
  812.     sprintf(tmp_20k_buf,
  813.         "Mail-check-interval \"%s\" not supported.  Using 15 seconds.",
  814.         VAR_MAILCHECK);
  815.     init_error(ps, tmp_20k_buf);
  816.     timeout = 15;
  817.     }
  818.  
  819.     set_current_val(&vars[V_NEWSRC_PATH], TRUE, TRUE);
  820.     if(ps_global->VAR_NEWSRC_PATH && ps_global->VAR_NEWSRC_PATH[0])
  821.       mail_parameters(NULL, SET_NEWSRC, (void *)ps_global->VAR_NEWSRC_PATH);
  822.  
  823.     set_current_val(&vars[V_NEWS_ACTIVE_PATH], TRUE, TRUE);
  824.     if(ps_global->VAR_NEWS_ACTIVE_PATH)
  825.       mail_parameters(NULL, SET_NEWSACTIVE,
  826.               (void *)ps_global->VAR_NEWS_ACTIVE_PATH);
  827.  
  828.     set_current_val(&vars[V_NEWS_SPOOL_DIR], TRUE, TRUE);
  829.     if(ps_global->VAR_NEWS_SPOOL_DIR)
  830.       mail_parameters(NULL, SET_NEWSSPOOL,
  831.               (void *)ps_global->VAR_NEWS_SPOOL_DIR);
  832.  
  833.     /* guarantee a save default */
  834.     set_current_val(&vars[V_DEFAULT_SAVE_FOLDER], TRUE, TRUE);
  835.     if(!VAR_DEFAULT_SAVE_FOLDER || !VAR_DEFAULT_SAVE_FOLDER[0])
  836.       set_variable(V_DEFAULT_SAVE_FOLDER,
  837.            (GLO_DEFAULT_SAVE_FOLDER && GLO_DEFAULT_SAVE_FOLDER[0])
  838.              ? GLO_DEFAULT_SAVE_FOLDER
  839.              : DEFAULT_SAVE, 0);
  840.  
  841.     /* obsolete, backwards compatibility */
  842.     set_current_val(&vars[V_FEATURE_LEVEL], TRUE, TRUE);
  843.     if(strucmp(VAR_FEATURE_LEVEL, "seedling") == 0)
  844.       obs_feature_level = Seedling;
  845.     else if(strucmp(VAR_FEATURE_LEVEL, "old-growth") == 0)
  846.       obs_feature_level = Seasoned;
  847.     else
  848.       obs_feature_level = Sapling;
  849.  
  850.     /* obsolete, backwards compatibility */
  851.     set_current_val(&vars[V_OLD_STYLE_REPLY], TRUE, TRUE);
  852.     obs_old_style_reply = !strucmp(VAR_OLD_STYLE_REPLY, "yes");
  853.  
  854.     set_current_val(&vars[V_SIGNATURE_FILE], TRUE, TRUE);
  855.     set_current_val(&vars[V_CHAR_SET], TRUE, TRUE);
  856.     set_current_val(&vars[V_GLOB_ADDRBOOK], TRUE, TRUE);
  857.     set_current_val(&vars[V_ADDRESSBOOK], TRUE, TRUE);
  858.     set_current_val(&vars[V_FORCED_ABOOK_ENTRY], TRUE, TRUE);
  859.     set_current_val(&vars[V_NNTP_SERVER], TRUE, TRUE);
  860.     for(i = 0; VAR_NNTP_SERVER && VAR_NNTP_SERVER[i]; i++)
  861.       removing_quotes(VAR_NNTP_SERVER[i]);
  862.  
  863.  
  864.     set_current_val(&vars[V_VIEW_HEADERS], TRUE, TRUE);
  865.     /* strip spaces and colons */
  866.     if(ps->VAR_VIEW_HEADERS){
  867.     for(s = ps->VAR_VIEW_HEADERS; (q = *s) != NULL; s++){
  868.         if(q[0]){
  869.         removing_leading_white_space(q);
  870.         /* look for colon or space or end */
  871.         for(p = q; *p && !isspace(*p) && *p != ':'; p++)
  872.           ;/* do nothing */
  873.         
  874.         *p = '\0';
  875.         if(strucmp(q, ALL_EXCEPT) == 0)
  876.           ps->view_all_except = 1;
  877.         }
  878.     }
  879.     }
  880.  
  881.     set_current_val(&vars[V_UPLOAD_CMD], TRUE, TRUE);
  882.     set_current_val(&vars[V_UPLOAD_CMD_PREFIX], TRUE, TRUE);
  883.     set_current_val(&vars[V_DOWNLOAD_CMD], TRUE, TRUE);
  884.     set_current_val(&vars[V_DOWNLOAD_CMD_PREFIX], TRUE, TRUE);
  885.     set_current_val(&vars[V_MAILCAP_PATH], TRUE, TRUE);
  886.     set_current_val(&vars[V_MIMETYPE_PATH], TRUE, TRUE);
  887.     set_current_val(&vars[V_TCPOPENTIMEO], TRUE, TRUE);
  888.     set_current_val(&vars[V_RSHOPENTIMEO], TRUE, TRUE);
  889.  
  890. #ifdef NEWBB
  891.     set_current_val(&vars[V_NNTP_NEW_GROUP_TIME], TRUE, TRUE);
  892.     if(ps_global->VAR_NNTP_NEW_GROUP_TIME == NULL ||
  893.        strlen(ps_global->VAR_NNTP_NEW_GROUP_TIME) <= 0){
  894.         /* If not set, set to two weeks ago */
  895.         long now  = time(0) - 24 * 3600 * 14; /* Two weeks ago */
  896.         set_variable(V_NNTP_NEW_GROUP_TIME, ctime(&now), 0);
  897.     }
  898. #endif
  899.  
  900. #if defined(DOS) || defined(OS2)
  901. #ifndef    _WINDOWS
  902.     /*
  903.      * Handle setting up page table IF running DOS 3.30 or greater
  904.      */
  905.     if(strucmp(ps_global->VAR_CHAR_SET, "us-ascii") != 0){
  906. #ifdef DOS
  907.     unsigned long ver;
  908.         extern unsigned int dos_version();
  909.         extern          int dos_codepage();
  910. #endif
  911.     extern unsigned char *read_xtable();
  912.     extern unsigned char  cp437L1[], cp850L1[], cp860L1[], cp863L1[],
  913.                   cp865L1[], cp866L5[];
  914.     extern unsigned char  L1cp437[], L1cp850[], L1cp860[], L1cp863[],
  915.                   L1cp865[], L5cp866[];
  916.  
  917.     /* suck in the translation table */
  918. #ifdef DOS
  919.     if(((ver = dos_version()) & 0x00ff) > 3 
  920.        || ((ver & 0x00ff) == 3 && (ver >> 8) >= 30)){
  921. #else
  922.     {
  923. #endif
  924.         char *in_table  = getenv("ISO_TO_CP"),
  925.              *out_table = getenv("CP_TO_ISO");
  926.  
  927.         if(out_table)
  928.           xlate_from_codepage = read_xtable(out_table);
  929.  
  930.         if(in_table)
  931.           xlate_to_codepage = read_xtable(in_table);
  932.  
  933.         /*
  934.          * if tables not already set, do the best we can...
  935.          */
  936.         switch(dos_codepage()){
  937.           case 437: /* latin-1 */
  938.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-1") == 0){
  939.             if(!xlate_from_codepage)
  940.               xlate_from_codepage = cp437L1;
  941.  
  942.             if(!xlate_to_codepage)
  943.               xlate_to_codepage   = L1cp437;
  944.         }
  945.  
  946.         break;
  947.           case 850: /* latin-1 */
  948.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-1") == 0){
  949.             if(!xlate_from_codepage)
  950.               xlate_from_codepage = cp850L1;
  951.  
  952.             if(!xlate_to_codepage)
  953.               xlate_to_codepage = L1cp850;
  954.         }
  955.  
  956.         break;
  957.           case 860: /* latin-1 */
  958.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-1") == 0){
  959.             if(!xlate_from_codepage)
  960.               xlate_from_codepage = cp860L1;
  961.  
  962.             if(!xlate_to_codepage)
  963.               xlate_to_codepage   = L1cp860;
  964.         }
  965.  
  966.         break;
  967.           case 863: /* latin-1 */
  968.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-1") == 0){
  969.             if(!xlate_from_codepage)
  970.               xlate_from_codepage = cp863L1;
  971.  
  972.             if(!xlate_to_codepage)
  973.               xlate_to_codepage   = L1cp863;
  974.         }
  975.  
  976.         break;
  977.           case 865: /* latin-1 */
  978.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-1") == 0){
  979.             if(!xlate_from_codepage)
  980.               xlate_from_codepage = cp865L1;
  981.  
  982.             if(!xlate_to_codepage)
  983.               xlate_to_codepage   = L1cp865;
  984.         }
  985.  
  986.         break;
  987.           case 866: /* latin-5 */
  988.         if(strucmp(ps_global->VAR_CHAR_SET, "iso-8859-5") == 0){
  989.             if(!xlate_from_codepage)
  990.               xlate_from_codepage = cp866L5;
  991.  
  992.             if(!xlate_to_codepage)
  993.               xlate_to_codepage   = L5cp866;
  994.         }
  995.  
  996.         break;
  997.           default:
  998.         break;
  999.         }
  1000.     }
  1001.     }
  1002. #endif
  1003.  
  1004.     set_current_val(&vars[V_FOLDER_EXTENSION], TRUE, TRUE);
  1005.     if(ps_global->VAR_FOLDER_EXTENSION)
  1006.       mail_parameters(NULL, SET_EXTENSION, 
  1007.               (void *)ps_global->VAR_FOLDER_EXTENSION);
  1008.  
  1009.     set_current_val(&vars[V_NORM_FORE_COLOR], TRUE, TRUE);
  1010.     if(ps_global->VAR_NORM_FORE_COLOR)
  1011.       pico_nfcolor(ps_global->VAR_NORM_FORE_COLOR);
  1012.  
  1013.     set_current_val(&vars[V_NORM_BACK_COLOR], TRUE, TRUE);
  1014.     if(ps_global->VAR_NORM_BACK_COLOR)
  1015.       pico_nbcolor(ps_global->VAR_NORM_BACK_COLOR);
  1016.  
  1017.     set_current_val(&vars[V_REV_FORE_COLOR], TRUE, TRUE);
  1018.     if(ps_global->VAR_REV_FORE_COLOR)
  1019.       pico_rfcolor(ps_global->VAR_REV_FORE_COLOR);
  1020.  
  1021.     set_current_val(&vars[V_REV_BACK_COLOR], TRUE, TRUE);
  1022.     if(ps_global->VAR_REV_BACK_COLOR)
  1023.       pico_rbcolor(ps_global->VAR_REV_BACK_COLOR);
  1024.  
  1025. #ifdef    _WINDOWS
  1026.     set_current_val(&vars[V_FONT_NAME], TRUE, TRUE);
  1027.     set_current_val(&vars[V_FONT_SIZE], TRUE, TRUE);
  1028.     set_current_val(&vars[V_FONT_STYLE], TRUE, TRUE);
  1029.     set_current_val(&vars[V_WINDOW_POSITION], TRUE, TRUE);
  1030.  
  1031.     mswin_setwindow (ps_global->VAR_FONT_NAME, ps_global->VAR_FONT_SIZE, 
  1032.             ps_global->VAR_FONT_STYLE, ps_global->VAR_WINDOW_POSITION);
  1033.     set_current_val(&vars[V_PRINT_FONT_NAME], TRUE, TRUE);
  1034.     set_current_val(&vars[V_PRINT_FONT_SIZE], TRUE, TRUE);
  1035.     set_current_val(&vars[V_PRINT_FONT_STYLE], TRUE, TRUE);
  1036.     mswin_setprintfont (ps_global->VAR_PRINT_FONT_NAME,
  1037.             ps_global->VAR_PRINT_FONT_SIZE,
  1038.             ps_global->VAR_PRINT_FONT_STYLE);
  1039.  
  1040.     {
  1041.     char **help_text = get_help_text (h_pine_for_windows, NULL);
  1042.  
  1043.     if (help_text != NULL)
  1044.       mswin_sethelptext ("PC-Pine For Windows", NULL, 0, help_text);
  1045.     }
  1046.  
  1047.     mswin_setclosetext ("Use the \"Q\" command to exit Pine.");
  1048. #endif    /* _WINDOWS */
  1049. #endif    /* DOS */
  1050.  
  1051.     set_current_val(&vars[V_LAST_VERS_USED], TRUE, TRUE);
  1052.     /*
  1053.      * Here's the deal.  We're not really a new version if our
  1054.      * version number looks like: <number><dot><number><number><alpha>
  1055.      * The <alpha> on the end is key meaning its just a bug-fix patch.
  1056.      * Otherwise just do lexicographic comparision...
  1057.      */
  1058.     if(VAR_LAST_VERS_USED
  1059.        && ((isdigit(PINE_VERSION[0]) && PINE_VERSION[1] == '.'
  1060.         && isdigit(PINE_VERSION[2]) && isdigit(PINE_VERSION[3])
  1061.         && isalpha(PINE_VERSION[4])
  1062.         && strncmp(VAR_LAST_VERS_USED, PINE_VERSION, 4) >= 0)
  1063.        || (strcmp(VAR_LAST_VERS_USED, PINE_VERSION) >= 0))){
  1064.     ps->show_new_version = 0;
  1065.     }
  1066.     else{
  1067.         if(VAR_LAST_VERS_USED && strcmp(VAR_LAST_VERS_USED, "3.90") >= 0)
  1068.             ps->pre390 = 0;
  1069.         else
  1070.             ps->pre390 = 1;
  1071.         ps->show_new_version = 1;
  1072.     }
  1073.     /* want to write new version to pinerc */
  1074.     if(ps->show_new_version)
  1075.       set_variable(V_LAST_VERS_USED, pine_version, 1);
  1076.     
  1077.     /* Obsolete, backwards compatibility */
  1078.     set_current_val(&vars[V_ELM_STYLE_SAVE], TRUE, TRUE);
  1079.     /* Also obsolete */
  1080.     set_current_val(&vars[V_SAVE_BY_SENDER], TRUE, TRUE);
  1081.     if(!strucmp(VAR_ELM_STYLE_SAVE, "yes"))
  1082.       set_variable(V_SAVE_BY_SENDER, "yes", 1);
  1083.     obs_save_by_sender = !strucmp(VAR_SAVE_BY_SENDER, "yes");
  1084.  
  1085.     /*
  1086.      * mail-directory variable is obsolete, put its value in
  1087.      * folder-collection list if that list is blank...
  1088.      */
  1089.     set_current_val(&vars[V_MAIL_DIRECTORY], TRUE, TRUE);
  1090.     set_current_val(&vars[V_PRUNED_FOLDERS], TRUE, TRUE);
  1091.     set_current_val(&vars[V_ARCHIVED_FOLDERS], TRUE, TRUE);
  1092.     set_current_val(&vars[V_INCOMING_FOLDERS], TRUE, TRUE);
  1093.     set_current_val(&vars[V_NEWS_SPEC], TRUE, TRUE);
  1094.     set_current_val(&vars[V_FOLDER_SPEC], TRUE, TRUE);
  1095.     /*
  1096.      * If there's no spec'd folder collection somewhere, set the current
  1097.      * value to the default, built from the mail directory...
  1098.      */
  1099.     if(!VAR_FOLDER_SPEC){
  1100.     build_path(tmp_20k_buf, VAR_MAIL_DIRECTORY, "[]");
  1101.     VAR_FOLDER_SPEC = parse_list(tmp_20k_buf, 1, NULL);
  1102.     }
  1103.  
  1104.     set_current_val(&vars[V_SORT_KEY], TRUE, TRUE);
  1105.     if(decode_sort(ps, VAR_SORT_KEY) == -1){
  1106.         if(!struncmp(VAR_SORT_KEY, "to", 2) ||
  1107.         !struncmp(VAR_SORT_KEY, "cc", 2)){
  1108.        sprintf(tmp_20k_buf, "Sort type \"%s\" is not implemented yet\n",
  1109.            VAR_SORT_KEY);
  1110.        init_error(ps, tmp_20k_buf);
  1111.     }else{
  1112.        fprintf(stderr, "Sort type \"%s\" is invalid\n", VAR_SORT_KEY);
  1113.        exit(-1);
  1114.     }
  1115.     }
  1116.  
  1117.     set_current_val(&vars[V_SAVED_MSG_NAME_RULE], TRUE, TRUE);
  1118.     {int        i;
  1119.      NAMEVAL_S *v;
  1120.      for(i = 0; v = save_msg_rules(i); i++)
  1121.        if(!strucmp(VAR_SAVED_MSG_NAME_RULE, v->name)){
  1122.        if((ps_global->save_msg_rule = v->value) == MSG_RULE_DEFLT){
  1123.            if(!strucmp(USR_SAVED_MSG_NAME_RULE,
  1124.                v->name))
  1125.          obs_save_by_sender = 0;  /* don't overwrite */
  1126.        }
  1127.  
  1128.        break;
  1129.        }
  1130.     }
  1131.  
  1132.     set_current_val(&vars[V_FCC_RULE], TRUE, TRUE);
  1133.     {int        i;
  1134.      NAMEVAL_S *v;
  1135.      for(i = 0; v = fcc_rules(i); i++)
  1136.        if(!strucmp(VAR_FCC_RULE, v->name)){
  1137.        ps_global->fcc_rule = v->value;
  1138.        break;
  1139.        }
  1140.     }
  1141.  
  1142.     set_current_val(&vars[V_AB_SORT_RULE], TRUE, TRUE);
  1143.     {int        i;
  1144.      NAMEVAL_S *v;
  1145.      for(i = 0; v = ab_sort_rules(i); i++)
  1146.        if(!strucmp(VAR_AB_SORT_RULE, v->name)){
  1147.        ps_global->ab_sort_rule = v->value;
  1148.        break;
  1149.        }
  1150.     }
  1151.  
  1152.     set_current_val(&vars[V_GOTO_DEFAULT_RULE], TRUE, TRUE);
  1153.     {int        i;
  1154.      NAMEVAL_S *v;
  1155.      for(i = 0; v = goto_rules(i); i++)
  1156.        if(!strucmp(VAR_GOTO_DEFAULT_RULE, v->name)){
  1157.        ps_global->goto_default_rule = v->value;
  1158.        break;
  1159.        }
  1160.     }
  1161.  
  1162.     /* backwards compatibility */
  1163.     if(obs_save_by_sender){
  1164.         ps->save_msg_rule = MSG_RULE_FROM;
  1165.     set_variable(V_SAVED_MSG_NAME_RULE, "by-from", 1);
  1166.     }
  1167.  
  1168.     set_feature_list_current_val(&vars[V_FEATURE_LIST]);
  1169.     process_feature_list(ps, VAR_FEATURE_LIST,
  1170.            (obs_feature_level == Seasoned) ? 1 : 0,
  1171.        obs_header_in_reply, obs_old_style_reply);
  1172.  
  1173.     /* this should come after process_feature_list because of use_fkeys */
  1174.     if(!ps->start_in_index)
  1175.         set_current_val(&vars[V_INIT_CMD_LIST], FALSE, TRUE);
  1176.     if(VAR_INIT_CMD_LIST)
  1177.         process_init_cmds(ps, VAR_INIT_CMD_LIST);
  1178.  
  1179. #ifdef    _WINDOWS
  1180.     mswin_set_quit_confirm (F_OFF(F_QUIT_WO_CONFIRM, ps_global));
  1181. #endif    /* _WINDOWS */
  1182.  
  1183. #ifdef DEBUG
  1184.     if(debugfile){
  1185.     gf_io_t pc;
  1186.  
  1187.     gf_set_writec(&pc, debugfile, 0L, FileStar);
  1188.     if(do_debug(debugfile))
  1189.       dump_config(ps, pc);
  1190.     }
  1191. #endif /* DEBUG */
  1192. }
  1193.  
  1194.  
  1195. /*
  1196.  * free_vars -- give back resources acquired when we defined the
  1197.  *        variables list
  1198.  */
  1199. void
  1200. free_vars(ps)
  1201.     struct pine *ps;
  1202. {
  1203.     register int i;
  1204.  
  1205.     for(i = 0; ps && i <= V_LAST_VAR; i++)
  1206.       if(ps->vars[i].is_list){
  1207.       char **l;
  1208.  
  1209.       if(l = ps->vars[i].current_val.l){
  1210.           for( ; *l; l++)
  1211.         fs_give((void **)l);
  1212.  
  1213.           fs_give((void **)&ps->vars[i].current_val.l);
  1214.       }
  1215.  
  1216.       if(l = ps->vars[i].user_val.l){
  1217.           for( ; *l; l++)
  1218.         fs_give((void **)l);
  1219.  
  1220.           fs_give((void **)&ps->vars[i].user_val.l);
  1221.       }
  1222.  
  1223.       if(l = ps->vars[i].global_val.l){
  1224.           for( ; *l; l++)
  1225.         fs_give((void **)l);
  1226.  
  1227.           fs_give((void **)&ps->vars[i].global_val.l);
  1228.       }
  1229.  
  1230.       if(l = ps->vars[i].fixed_val.l){
  1231.           for( ; *l; l++)
  1232.         fs_give((void **)l);
  1233.  
  1234.           fs_give((void **)&ps->vars[i].fixed_val.l);
  1235.       }
  1236.  
  1237.       if(l = ps->vars[i].cmdline_val.l){
  1238.           for( ; *l; l++)
  1239.         fs_give((void **)l);
  1240.  
  1241.           fs_give((void **)&ps->vars[i].cmdline_val.l);
  1242.       }
  1243.       }
  1244.       else{
  1245.       if(ps->vars[i].current_val.p)
  1246.         fs_give((void **)&ps->vars[i].current_val.p);
  1247.  
  1248.       if(ps->vars[i].user_val.p)
  1249.         fs_give((void **)&ps->vars[i].user_val.p);
  1250.  
  1251.       if(ps->vars[i].global_val.p)
  1252.         fs_give((void **)&ps->vars[i].global_val.p);
  1253.  
  1254.       if(ps->vars[i].fixed_val.p)
  1255.         fs_give((void **)&ps->vars[i].fixed_val.p);
  1256.  
  1257.       if(ps->vars[i].cmdline_val.p)
  1258.         fs_give((void **)&ps->vars[i].cmdline_val.p);
  1259.       }
  1260. }
  1261.  
  1262.  
  1263. /*
  1264.  * Standard way to get at feature list members...
  1265.  */
  1266. NAMEVAL_S *
  1267. feature_list(index)
  1268.     int index;
  1269. {
  1270.     /*
  1271.      * This list is alphabatized by feature string, but the 
  1272.      * macro values need not be ordered.
  1273.      */
  1274.     static NAMEVAL_S feat_list[] = {
  1275.     {"old-growth",                F_OLD_GROWTH},
  1276. #if !defined(DOS) && !defined(OS2)
  1277.     {"allow-talk",                F_ALLOW_TALK},
  1278. #endif
  1279.     {"assume-slow-link",            F_FORCE_LOW_SPEED},
  1280.     {"auto-move-read-msgs",            F_AUTO_READ_MSGS},
  1281.     {"auto-open-next-unread",        F_AUTO_OPEN_NEXT_UNREAD},
  1282.     {"auto-zoom-after-select",        F_AUTO_ZOOM},
  1283.     {"auto-unzoom-after-apply",        F_AUTO_UNZOOM},
  1284.     {"compose-cut-from-cursor",        F_DEL_FROM_DOT},
  1285.     {"compose-maps-delete-key-to-ctrl-d",    F_COMPOSE_MAPS_DEL},
  1286.     {"compose-rejects-unqualified-addrs",    F_COMPOSE_REJECTS_UNQUAL},
  1287.     {"compose-send-offers-first-filter",    F_FIRST_SEND_FILTER_DFLT},
  1288.     {"compose-sets-newsgroup-without-confirm", F_COMPOSE_TO_NEWSGRP},
  1289.     {"delete-skips-deleted",        F_DEL_SKIPS_DEL},
  1290.     {"disable-config-cmd",            F_DISABLE_CONFIG_SCREEN},
  1291.     {"disable-keyboard-lock-cmd",        F_DISABLE_KBLOCK_CMD},
  1292.     {"disable-keymenu",            F_BLANK_KEYMENU},
  1293.     {"disable-password-cmd",        F_DISABLE_PASSWORD_CMD},
  1294.     {"disable-update-cmd",            F_DISABLE_UPDATE_CMD},
  1295.     {"disable-signature-edit-cmd",        F_DISABLE_SIGEDIT_CMD},
  1296.     {"enable-8bit-esmtp-negotiation",    F_ENABLE_8BIT},
  1297.     {"enable-8bit-nntp-posting",        F_ENABLE_8BIT_NNTP},
  1298.     {"enable-aggregate-command-set",    F_ENABLE_AGG_OPS},
  1299.     {"enable-alternate-editor-cmd",        F_ENABLE_ALT_ED},
  1300.     {"enable-alternate-editor-implicitly",    F_ALT_ED_NOW},
  1301.     {"enable-bounce-cmd",            F_ENABLE_BOUNCE},
  1302.     {"enable-cruise-mode",            F_ENABLE_SPACE_AS_TAB},
  1303.     {"enable-cruise-mode-delete",        F_ENABLE_TAB_DELETES},
  1304.     {"enable-dot-files",            F_ENABLE_DOT_FILES},
  1305.     {"enable-dot-folders",            F_ENABLE_DOT_FOLDERS},
  1306.     {"enable-flag-cmd",            F_ENABLE_FLAG},
  1307.     {"enable-flag-screen-implicitly",    F_FLAG_SCREEN_DFLT},
  1308.     {"enable-full-header-cmd",        F_ENABLE_FULL_HDR},
  1309.     {"enable-incoming-folders",        F_ENABLE_INCOMING},
  1310.     {"enable-jump-shortcut",        F_ENABLE_JUMP},
  1311.     {"enable-mail-check-cue",        F_SHOW_DELAY_CUE},
  1312.     {"enable-mouse-in-xterm",        F_ENABLE_MOUSE},
  1313.     {"enable-newmail-in-xterm-icon",    F_ENABLE_XTERM_NEWMAIL},
  1314.     {"enable-suspend",            F_CAN_SUSPEND},
  1315.     {"enable-tab-completion",        F_ENABLE_TAB_COMPLETE},
  1316.     {"enable-unix-pipe-cmd",        F_ENABLE_PIPE},
  1317.     {"enable-verbose-smtp-posting",        F_VERBOSE_POST},
  1318.     {"expanded-view-of-addressbooks",    F_EXPANDED_ADDRBOOKS},
  1319.     {"expanded-view-of-folders",        F_EXPANDED_FOLDERS},
  1320.     {"expunge-without-confirm",        F_AUTO_EXPUNGE},
  1321.     {"fcc-on-bounce",            F_FCC_ON_BOUNCE},
  1322.     {"include-attachments-in-reply",    F_ATTACHMENTS_IN_REPLY},
  1323.     {"include-header-in-reply",        F_INCLUDE_HEADER},
  1324.     {"include-text-in-reply",        F_AUTO_INCLUDE_IN_REPLY},
  1325.     {"news-approximates-new-status",    F_FAKE_NEW_IN_NEWS},
  1326.     {"news-post-without-validation",    F_NO_NEWS_VALIDATION},
  1327.     {"news-read-in-newsrc-order",        F_READ_IN_NEWSRC_ORDER},
  1328.     {"pass-control-characters-as-is",    F_PASS_CONTROL_CHARS},
  1329.     {"preserve-start-stop-characters",    F_PRESERVE_START_STOP},
  1330.     {"print-offers-custom-cmd-prompt",    F_CUSTOM_PRINT},
  1331.     {"print-index-enabled",            F_PRINT_INDEX},
  1332.     {"print-formfeed-between-messages",    F_AGG_PRINT_FF},
  1333.     {"quell-dead-letter-on-cancel",        F_QUELL_DEAD_LETTER},
  1334.     {"quell-lock-failure-warnings",        F_QUELL_LOCK_FAILURE_MSGS},
  1335.     {"quell-status-message-beeping",    F_QUELL_BEEPS},
  1336.     {"quell-user-lookup-in-passwd-file",    F_QUELL_LOCAL_LOOKUP},
  1337.     {"quit-without-confirm",        F_QUIT_WO_CONFIRM},
  1338.     {"reply-always-uses-reply-to",        F_AUTO_REPLY_TO},
  1339.     {"save-will-quote-leading-froms",    F_QUOTE_ALL_FROMS},
  1340.     {"save-will-not-delete",        F_SAVE_WONT_DELETE},
  1341.     {"save-will-advance",            F_SAVE_ADVANCES},
  1342.     {"select-without-confirm",        F_SELECT_WO_CONFIRM},
  1343.     {"show-cursor",                F_SHOW_CURSOR},
  1344.     {"show-selected-in-boldface",        F_SELECTED_SHOWN_BOLD},
  1345.     {"signature-at-bottom",            F_SIG_AT_BOTTOM},
  1346.     {"single-column-folder-list",        F_VERT_FOLDER_LIST},
  1347.     {"tab-visits-next-new-message-only",    F_TAB_TO_NEW},
  1348.     {"use-current-dir",            F_USE_CURRENT_DIR},
  1349.     {"use-function-keys",            F_USE_FK},
  1350.     {"use-sender-not-x-sender",        F_USE_SENDER_NOT_X},
  1351.     {"use-subshell-for-suspend",        F_SUSPEND_SPAWNS}
  1352.     };
  1353.  
  1354.     return((index >= 0 && index < (sizeof(feat_list)/sizeof(feat_list[0])))
  1355.        ? &feat_list[index] : NULL);
  1356. }
  1357.  
  1358.  
  1359. /*
  1360.  * All the arguments past "list" are the backwards compatibility hacks.
  1361.  */
  1362. void
  1363. process_feature_list(ps, list, old_growth, hir, osr)
  1364.     struct pine *ps;
  1365.     char **list;
  1366.     int old_growth, hir, osr;
  1367. {
  1368.     register struct variable *vars = ps->vars;
  1369.     register char            *q;
  1370.     char                    **p,
  1371.                              *lvalue[LARGEST_BITMAP];
  1372.     int                       i,
  1373.                               yorn;
  1374.     NAMEVAL_S             *feat;
  1375.  
  1376.  
  1377.     /* backwards compatibility */
  1378.     if(hir)
  1379.     F_TURN_ON(F_INCLUDE_HEADER, ps);
  1380.  
  1381.     /* ditto */
  1382.     if(osr)
  1383.     F_TURN_ON(F_SIG_AT_BOTTOM, ps);
  1384.  
  1385.     /* ditto */
  1386.     if(old_growth)
  1387.         set_old_growth_bits(ps, 0);
  1388.  
  1389.     /* now run through the list (global, user, and cmd_line lists are here) */
  1390.     if(list){
  1391.       for(p = list; (q = *p) != NULL; p++){
  1392.     if(struncmp(q, "no-", 3) == 0){
  1393.       yorn = 0;
  1394.       q += 3;
  1395.     }else{
  1396.       yorn = 1;
  1397.     }
  1398.  
  1399.     for(i = 0; (feat = feature_list(i)) != NULL; i++){
  1400.       if(strucmp(q, feat->name) == 0){
  1401.         if(feat->value == F_OLD_GROWTH){
  1402.           set_old_growth_bits(ps, yorn);
  1403.         }else{
  1404.           F_SET(feat->value, ps, yorn);
  1405.         }
  1406.         break;
  1407.       }
  1408.     }
  1409.     /* if it wasn't in that list */
  1410.     if(feat == NULL)
  1411.           dprint(1, (debugfile,"Unrecognized feature in feature-list (%s%s)\n",
  1412.              (yorn ? "" : "no-"), q));
  1413.       }
  1414.     }
  1415.  
  1416.     /*
  1417.      * Turn on gratuitous '>From ' quoting, if requested...
  1418.      */
  1419.     mail_parameters(NULL, SET_FROMWIDGET,
  1420.             (void  *)(F_ON(F_QUOTE_ALL_FROMS, ps) ? 1 : 0));
  1421.  
  1422.     /*
  1423.      * Turn off .lock creation complaints...
  1424.      */
  1425.     if(F_ON(F_QUELL_LOCK_FAILURE_MSGS, ps))
  1426.       mail_parameters(NULL, SET_LOCKEACCESERROR, (void *) 0);
  1427.  
  1428.     if(F_ON(F_USE_FK, ps))
  1429.       ps->orig_use_fkeys = 1;
  1430.  
  1431.     /* Will we have to build a new list? */
  1432.     if(!(old_growth || hir || osr))
  1433.     return;
  1434.  
  1435.     /*
  1436.      * Build a new list for feature-list.  The only reason we ever need to
  1437.      * do this is if one of the obsolete options is being converted
  1438.      * into a feature-list item, and it isn't already included in the user's
  1439.      * feature-list.
  1440.      */
  1441.     i = 0;
  1442.     for(p = USR_FEATURE_LIST; p && (q = *p); p++){
  1443.       /* already have it or cancelled it, don't need to add later */
  1444.       if(hir && (strucmp(q, "include-header-in-reply") == 0 ||
  1445.                              strucmp(q, "no-include-header-in-reply") == 0)){
  1446.     hir = 0;
  1447.       }else if(osr && (strucmp(q, "signature-at-bottom") == 0 ||
  1448.                              strucmp(q, "no-signature-at-bottom") == 0)){
  1449.     osr = 0;
  1450.       }else if(old_growth && (strucmp(q, "old-growth") == 0 ||
  1451.                              strucmp(q, "no-old-growth") == 0)){
  1452.     old_growth = 0;
  1453.       }
  1454.       lvalue[i++] = cpystr(q);
  1455.     }
  1456.  
  1457.     /* check to see if we still need to build a new list */
  1458.     if(!(old_growth || hir || osr))
  1459.     return;
  1460.  
  1461.     if(hir)
  1462.       lvalue[i++] = "include-header-in-reply";
  1463.     if(osr)
  1464.       lvalue[i++] = "signature-at-bottom";
  1465.     if(old_growth)
  1466.       lvalue[i++] = "old-growth";
  1467.     lvalue[i] = NULL;
  1468.     set_variable_list(V_FEATURE_LIST, lvalue);
  1469. }
  1470.  
  1471.  
  1472.  
  1473. /*
  1474.  * set_old_growth_bits - Command used to set or unset old growth set
  1475.  *             of features
  1476.  */
  1477. void
  1478. set_old_growth_bits(ps, val)
  1479.     struct pine *ps;
  1480.     int          val;
  1481. {
  1482.     int i;
  1483.  
  1484.     for(i = 1; i <= F_LAST_FEATURE; i++)
  1485.       if(test_old_growth_bits(ps, i))
  1486.     F_SET(i, ps, val);
  1487. }
  1488.  
  1489.  
  1490.  
  1491. /*
  1492.  * test_old_growth_bits - Test to see if all the old growth bits are on,
  1493.  *              *or* if a particular feature index is in the old
  1494.  *              growth set.
  1495.  *
  1496.  * WEIRD ALERT: if index == F_OLD_GROWTH bit values are tested
  1497.  *              otherwise a bits existence in the set is tested!!!
  1498.  *
  1499.  * BUG: this will break if an old growth feature number is ever >= 32.
  1500.  */
  1501. int
  1502. test_old_growth_bits(ps, index)
  1503.     struct pine *ps;
  1504.     int          index;
  1505. {
  1506.     /*
  1507.      * this list defines F_OLD_GROWTH set
  1508.      */
  1509.     static unsigned long old_growth_bits = ((1 << F_ENABLE_FULL_HDR)     |
  1510.                         (1 << F_ENABLE_PIPE)         |
  1511.                         (1 << F_ENABLE_TAB_COMPLETE) |
  1512.                         (1 << F_QUIT_WO_CONFIRM)     |
  1513.                         (1 << F_ENABLE_JUMP)         |
  1514.                         (1 << F_ENABLE_ALT_ED)       |
  1515.                         (1 << F_ENABLE_BOUNCE)       |
  1516.                         (1 << F_ENABLE_AGG_OPS)     |
  1517.                         (1 << F_ENABLE_FLAG)         |
  1518.                         (1 << F_CAN_SUSPEND));
  1519.     if(index >= 32)
  1520.     return(0);
  1521.  
  1522.     if(index == F_OLD_GROWTH){
  1523.     for(index = 1; index <= F_LAST_FEATURE; index++)
  1524.       if(((1 << index) & old_growth_bits) && F_OFF(index, ps))
  1525.         return(0);
  1526.  
  1527.     return(1);
  1528.     }
  1529.     else
  1530.       return((1 << index) & old_growth_bits);
  1531. }
  1532.  
  1533.  
  1534.  
  1535. /*
  1536.  * Standard way to get at save message rules...
  1537.  */
  1538. NAMEVAL_S *
  1539. save_msg_rules(index)
  1540.     int index;
  1541. {
  1542.     static NAMEVAL_S save_rules[] = {
  1543.     {"by-from",        MSG_RULE_FROM},
  1544.     {"by-nick-of-from",    MSG_RULE_NICK_FROM},
  1545.     {"by-fcc-of-from",    MSG_RULE_FCC_FROM},
  1546.     {"by-sender",        MSG_RULE_SENDER},
  1547.     {"by-nick-of-sender",    MSG_RULE_NICK_SENDER},
  1548.     {"by-fcc-of-sender",    MSG_RULE_FCC_SENDER},
  1549.     {"by-recipient",    MSG_RULE_RECIP},
  1550.     {"by-nick-of-recip",    MSG_RULE_NICK_RECIP},
  1551.     {"by-fcc-of-recip",    MSG_RULE_FCC_RECIP},
  1552.     {"last-folder-used",    MSG_RULE_LAST}, 
  1553.     {"default-folder",    MSG_RULE_DEFLT}
  1554.     };
  1555.  
  1556.     return((index >= 0 && index < (sizeof(save_rules)/sizeof(save_rules[0])))
  1557.        ? &save_rules[index] : NULL);
  1558. }
  1559.  
  1560.  
  1561. /*
  1562.  * Standard way to get at fcc rules...
  1563.  */
  1564. NAMEVAL_S *
  1565. fcc_rules(index)
  1566.     int index;
  1567. {
  1568.     static NAMEVAL_S f_rules[] = {
  1569.     {"default-fcc",        FCC_RULE_DEFLT}, 
  1570.     {"last-fcc-used",      FCC_RULE_LAST}, 
  1571.     {"by-recipient",       FCC_RULE_RECIP},
  1572.     {"by-nickname",        FCC_RULE_NICK},
  1573.     {"by-nick-then-recip", FCC_RULE_NICK_RECIP},
  1574.     {"current-folder",     FCC_RULE_CURRENT}
  1575.     };
  1576.  
  1577.     return((index >= 0 && index < (sizeof(f_rules)/sizeof(f_rules[0])))
  1578.        ? &f_rules[index] : NULL);
  1579. }
  1580.  
  1581.  
  1582. /*
  1583.  * Standard way to get at addrbook sort rules...
  1584.  */
  1585. NAMEVAL_S *
  1586. ab_sort_rules(index)
  1587.     int index;
  1588. {
  1589.     static NAMEVAL_S ab_rules[] = {
  1590.     {"fullname-with-lists-last",  AB_SORT_RULE_FULL_LISTS},
  1591.     {"fullname",                  AB_SORT_RULE_FULL}, 
  1592.     {"nickname-with-lists-last",  AB_SORT_RULE_NICK_LISTS},
  1593.     {"nickname",                  AB_SORT_RULE_NICK},
  1594.     {"dont-sort",                 AB_SORT_RULE_NONE}
  1595.     };
  1596.  
  1597.     return((index >= 0 && index < (sizeof(ab_rules)/sizeof(ab_rules[0])))
  1598.        ? &ab_rules[index] : NULL);
  1599. }
  1600.  
  1601.  
  1602. /*
  1603.  * Standard way to get at goto default rules...
  1604.  */
  1605. NAMEVAL_S *
  1606. goto_rules(index)
  1607.     int index;
  1608. {
  1609.     static NAMEVAL_S g_rules[] = {
  1610.     {"inbox-or-folder-in-recent-collection", GOTO_INBOX_RECENT_CLCTN},
  1611.     {"inbox-or-folder-in-first-collection",     GOTO_INBOX_FIRST_CLCTN},
  1612.     {"most-recent-folder",             GOTO_LAST_FLDR}
  1613.     };
  1614.  
  1615.     return((index >= 0 && index < (sizeof(g_rules)/sizeof(g_rules[0])))
  1616.        ? &g_rules[index] : NULL);
  1617. }
  1618.  
  1619.  
  1620. /*
  1621.  * The argument is an argument from the command line.  We check to see
  1622.  * if it is specifying an alternate value for one of the options that is
  1623.  * normally set in pinerc.  If so, we return 1 and set the appropriate
  1624.  * values in the variables array.
  1625.  */
  1626. int
  1627. pinerc_cmdline_opt(arg)
  1628.     char *arg;
  1629. {
  1630.     struct variable *v;
  1631.     char            *p,
  1632.                     *p1,
  1633.                     *value,
  1634.                    **lvalue;
  1635.     int              i;
  1636.  
  1637.     if(!arg || !arg[0])
  1638.       return 0;
  1639.  
  1640.     for(v = variables; v->name != NULL; v++){
  1641.       if(v->is_used && strncmp(v->name, arg, strlen(v->name)) == 0)
  1642.         break;
  1643.     }
  1644.  
  1645.     /* no match */
  1646.     if(v->name == NULL)
  1647.       return 0;
  1648.  
  1649.     if(v->is_obsolete || !v->is_user){
  1650.       fprintf(stderr, "Option \"%s\" is %s\n", v->name, v->is_obsolete ?
  1651.                        "obsolete" :
  1652.                        "not user settable");
  1653.       exit(-1);
  1654.     }
  1655.  
  1656.     /*----- Skip to '=' -----*/
  1657.     p1 = arg + strlen(v->name);
  1658.     while(*p1 && (*p1 == '\t' || *p1 == ' '))
  1659.       p1++;
  1660.  
  1661.     if(*p1 != '='){
  1662.       fprintf(stderr, "Missing \"=\" after -%s\n", v->name);
  1663.       exit(-1);
  1664.     }
  1665.  
  1666.     /* free mem */
  1667.     if(v->is_list){
  1668.       if(v->cmdline_val.l){
  1669.         char **p;
  1670.         for(p = v->cmdline_val.l; *p ; p++)
  1671.           fs_give((void **)p);
  1672.         fs_give((void **)&(v->cmdline_val.l));
  1673.       }
  1674.     }else{
  1675.       if(v->cmdline_val.p)
  1676.         fs_give((void **) &(v->cmdline_val.p));
  1677.     }
  1678.  
  1679.     p1++;
  1680.  
  1681.     /*----- Matched a variable, get its value ----*/
  1682.     while(*p1 == ' ' || *p1 == '\t')
  1683.       p1++;
  1684.     value = p1;
  1685.  
  1686.     if(*value == '\0'){
  1687.       if(v->is_list){
  1688.         v->cmdline_val.l = (char **)fs_get(2 * sizeof(char *));
  1689.     /*
  1690.      * we let people leave off the quotes on command line so that
  1691.      * they don't have to mess with shell quoting
  1692.      */
  1693.         v->cmdline_val.l[0] = cpystr("");
  1694.         v->cmdline_val.l[1] = NULL;
  1695.       }else{
  1696.         v->cmdline_val.p = cpystr("");
  1697.       }
  1698.       return 1;
  1699.     }
  1700.  
  1701.     /*--value is non-empty--*/
  1702.     if(*value == '"' && !v->is_list){
  1703.       value++;
  1704.       for(p1 = value; *p1 && *p1 != '"'; p1++);
  1705.         if(*p1 == '"')
  1706.           *p1 = '\0';
  1707.         else
  1708.           removing_trailing_white_space(value);
  1709.     }else{
  1710.       removing_trailing_white_space(value);
  1711.     }
  1712.  
  1713.     if(v->is_list){
  1714.       int   was_quoted = 0,
  1715.             count      = 1;
  1716.       char *error      = NULL;
  1717.  
  1718.       for(p1=value; *p1; p1++){        /* generous count of list elements */
  1719.         if(*p1 == '"')            /* ignore ',' if quoted   */
  1720.           was_quoted = (was_quoted) ? 0 : 1;
  1721.  
  1722.         if(*p1 == ',' && !was_quoted)
  1723.           count++;
  1724.       }
  1725.  
  1726.       lvalue = parse_list(value, count, &error);
  1727.       if(error){
  1728.     fprintf(stderr, "%s in %s = \"%s\"\n", error, v->name, value);
  1729.     exit(-1);
  1730.       }
  1731.       /*
  1732.        * Special case: turn "" strings into empty strings.
  1733.        * This allows users to turn off default lists.  For example,
  1734.        * if smtp-server is set then a user could override smtp-server
  1735.        * with smtp-server="".
  1736.        */
  1737.       for(i = 0; lvalue[i]; i++)
  1738.     if(lvalue[i][0] == '"' &&
  1739.        lvalue[i][1] == '"' &&
  1740.        lvalue[i][2] == '\0')
  1741.          lvalue[i][0] = '\0';
  1742.     }
  1743.  
  1744.     if(v->is_list)
  1745.       v->cmdline_val.l = lvalue;
  1746.     else
  1747.       v->cmdline_val.p = cpystr(value);
  1748.  
  1749.     return 1;
  1750. }
  1751.  
  1752.  
  1753. /*
  1754.  * Process the command list, changing function key notation into
  1755.  * lexical equivalents.
  1756.  */
  1757. void
  1758. process_init_cmds(ps, list)
  1759.     struct pine *ps;
  1760.     char **list;
  1761. {
  1762.     char **p;
  1763.     int i = 0;
  1764.     int j;
  1765. #define MAX_INIT_CMDS 500
  1766.     /* this is just a temporary stack array, the real one is allocated below */
  1767.     int i_cmds[MAX_INIT_CMDS];
  1768.     int fkeys = 0;
  1769.     int not_fkeys = 0;
  1770.   
  1771.     if(list){
  1772.       for(p = list; *p && i < MAX_INIT_CMDS; p++){
  1773.  
  1774.     /* regular character commands */
  1775.     if(strlen(*p) == 1){
  1776.  
  1777.       i_cmds[i++] = **p;
  1778.       not_fkeys++;
  1779.  
  1780.     }else if(strucmp(*p, "SPACE") == 0){
  1781.         i_cmds[i++] = ' ';
  1782.         not_fkeys++;
  1783.  
  1784.     }else if(strucmp(*p, "CR") == 0){
  1785.         i_cmds[i++] = '\n';
  1786.         not_fkeys++;
  1787.  
  1788.     }else if(strucmp(*p, "TAB") == 0){
  1789.         i_cmds[i++] = '\t';
  1790.         not_fkeys++;
  1791.  
  1792.     /* control chars */
  1793.     }else if(strlen(*p) == 2 && **p == '^'){
  1794.  
  1795.         i_cmds[i++] = ctrl(*((*p)+1));
  1796.  
  1797.     /* function keys */
  1798.     }else{
  1799.  
  1800.       fkeys++;
  1801.  
  1802.       if(**p == 'F' || **p == 'f'){
  1803.         int v;
  1804.  
  1805.         v = atoi((*p)+1);
  1806.         if(v >= 1 && v <= 12)
  1807.           i_cmds[i++] = PF1 + v - 1;
  1808.         else
  1809.           i_cmds[i++] = KEY_JUNK;
  1810.  
  1811.       }else if(strucmp(*p, "UP") == 0){
  1812.         i_cmds[i++] = KEY_UP;
  1813.       }else if(strucmp(*p, "DOWN") == 0){
  1814.         i_cmds[i++] = KEY_DOWN;
  1815.       }else if(strucmp(*p, "LEFT") == 0){
  1816.         i_cmds[i++] = KEY_LEFT;
  1817.       }else if(strucmp(*p, "RIGHT") == 0){
  1818.         i_cmds[i++] = KEY_RIGHT;
  1819.       }else{
  1820.         fkeys--;
  1821.         sprintf(tmp_20k_buf,
  1822.             "Bad initial keystroke \"%s\" (missing comma?)\n", *p);
  1823.         init_error(ps, tmp_20k_buf);
  1824.       }
  1825.     }
  1826.       }
  1827.     }
  1828.  
  1829.     /*
  1830.      * We don't handle the case where function keys are used to specify the
  1831.      * commands but some non-function key input is also required.  For example,
  1832.      * you might want to jump to a specific message number and view it
  1833.      * on start up.  To do that, you need to use character commands instead
  1834.      * of function key commands in the initial-keystroke-list.
  1835.      */
  1836.     if(fkeys && not_fkeys){
  1837.     init_error(ps,
  1838. "Mixed characters and function keys in \"initial-keystroke-list\", skipping!");
  1839.     i = 0;
  1840.     }
  1841.  
  1842.     if(fkeys && !not_fkeys)
  1843.       F_TURN_ON(F_USE_FK,ps);
  1844.     if(!fkeys && not_fkeys)
  1845.       F_TURN_OFF(F_USE_FK,ps);
  1846.  
  1847.     ps->initial_cmds = (int *)fs_get((i+1) * sizeof(int));
  1848.     ps->free_initial_cmds = ps->initial_cmds;
  1849.     for(j = 0; j < i; j++)
  1850.     ps->initial_cmds[j] = i_cmds[j];
  1851.     ps->initial_cmds[i] = 0;
  1852.     if(i)
  1853.       ps->in_init_seq = ps->save_in_init_seq = 1;
  1854. }
  1855.  
  1856.  
  1857. /*
  1858.  * Choose from the global default, command line args, pinerc values to set
  1859.  * the actual value of the variable that we will use.  Start at the top
  1860.  * and work down from higher to lower precedence.
  1861.  */
  1862. void    
  1863. set_current_val(var, expand, cmdline)
  1864.     struct variable *var;
  1865.     int              expand, cmdline;
  1866. {
  1867.     int    is_set[4];  /* to see if we should warn user about fixed var */
  1868.     char **tmp;
  1869.  
  1870.     dprint(9, (debugfile,
  1871.            "set_current_val(var num=%d, expand=%d, cmdline=%d)\n",
  1872.            var - ps_global->vars, expand, cmdline));
  1873.  
  1874.     if(var->is_list){  /* variable is a list */
  1875.     char **list = NULL;
  1876.     int    i, j;
  1877.  
  1878.     dprint(9, (debugfile, "is_list: name=%s\n", var->name));
  1879.  
  1880.     /*
  1881.      * It's possible for non-null list elements to expand to
  1882.      * nothing, so we have to be a little more intelligent about
  1883.      * pre-expanding the lists to make sure such lists are
  1884.      * treated like empty lists...
  1885.      */
  1886.     for(j = 0; j < 4; j++){
  1887.         char **t;
  1888.  
  1889.         /*
  1890.          * The first one that's set wins.
  1891.          */
  1892.         t = j==0 ? var->fixed_val.l :
  1893.         j==1 ? (cmdline) ? var->cmdline_val.l : NULL :
  1894.         j==2 ? var->user_val.l :
  1895.                var->global_val.l;
  1896.  
  1897.         is_set[j] = 0;
  1898.  
  1899.         if(t){
  1900.         if(!expand){
  1901.             is_set[j]++;
  1902.             if(!list)
  1903.               list = t;
  1904.         }
  1905.         else{
  1906.             for(i = 0; t[i]; i++){
  1907.             if(expand_variables(tmp_20k_buf, t[i])){
  1908.                 /* successful expand */
  1909.                 is_set[j]++;
  1910.                 if(!list)
  1911.                   list = t;
  1912.  
  1913.                 break;
  1914.             }
  1915.             }
  1916.         }
  1917.         }
  1918.     }
  1919.  
  1920.     /* Admin wants default, which is global_val. */
  1921.     if(var->is_fixed && var->fixed_val.l == NULL)
  1922.       list = var->global_val.l;
  1923.             
  1924.     if(var->current_val.l){     /* clean up any old values */
  1925.         for(tmp = var->current_val.l; *tmp ; tmp++)
  1926.           fs_give((void **)tmp);
  1927.  
  1928.         fs_give((void **)&var->current_val.l);
  1929.     }
  1930.  
  1931.     if(list){
  1932.         int cnt = 0;
  1933.  
  1934.         for(; list[cnt]; cnt++)    /* item count */
  1935.           ;/* do nothing */
  1936.  
  1937.         dprint(9, (debugfile, "counted %d items\n", cnt));
  1938.  
  1939.         var->current_val.l = (char **)fs_get((cnt+1)*sizeof(char *));
  1940.         tmp = var->current_val.l;
  1941.  
  1942.         for(i = 0; list[i]; i++){
  1943.         if(!expand)
  1944.           *tmp++ = cpystr(list[i]);
  1945.         else if(expand_variables(tmp_20k_buf, list[i]))
  1946.           *tmp++ = cpystr(tmp_20k_buf);
  1947.         }
  1948.  
  1949.         *tmp = NULL;
  1950.     }
  1951.     else
  1952.       var->current_val.l = NULL;
  1953.  
  1954.     }
  1955.  
  1956.     else{  /* variable is not a list */
  1957.     char *strvar = NULL;
  1958.     char *t;
  1959.     int   j;
  1960.  
  1961.     for(j = 0; j < 4; j++){
  1962.  
  1963.         t = j==0 ? var->fixed_val.p :
  1964.         j==1 ? (cmdline) ? var->cmdline_val.p : NULL :
  1965.         j==2 ? var->user_val.p :
  1966.                var->global_val.p;
  1967.  
  1968.         is_set[j] = 0;
  1969.  
  1970.         if(t){
  1971.         if(!expand){
  1972.             is_set[j]++;
  1973.             if(!strvar)
  1974.             strvar = t;
  1975.         }
  1976.         else if(expand_variables(tmp_20k_buf, t)){
  1977.             is_set[j]++;
  1978.             if(!strvar)
  1979.             strvar = t;
  1980.         }
  1981.         }
  1982.     }
  1983.  
  1984.     /* Admin wants default, which is global_val. */
  1985.     if(var->is_fixed && var->fixed_val.p == NULL)
  1986.       strvar = var->global_val.p;
  1987.  
  1988.     if(var->current_val.p)        /* free previous value */
  1989.       fs_give((void **)&var->current_val.p);
  1990.  
  1991.     if(strvar){
  1992.         if(!expand)
  1993.           var->current_val.p = cpystr(strvar);
  1994.         else{
  1995.         expand_variables(tmp_20k_buf, strvar);
  1996.         var->current_val.p = cpystr(tmp_20k_buf);
  1997.         }
  1998.     }
  1999.     else
  2000.       var->current_val.p = NULL;
  2001.     }
  2002.  
  2003.     if(var->is_fixed){
  2004.     char **list;
  2005.     int i, j, fixed_len, user_len;
  2006.  
  2007.     /*
  2008.      * sys mgr fixed this variable and user is trying to change it
  2009.      */
  2010.     if(is_set[2]){
  2011.         if(var->is_list){
  2012.         /* If same length and same contents, don't warn. */
  2013.         for(list=var->fixed_val.l; list && *list; list++)
  2014.           ;/* just counting */
  2015.  
  2016.         fixed_len = var->fixed_val.l ? (list - var->fixed_val.l) : 0;
  2017.         for(list=var->user_val.l; list && *list; list++)
  2018.           ;/* just counting */
  2019.  
  2020.         user_len = var->user_val.l ? (list - var->user_val.l) : 0;
  2021.         if(user_len == fixed_len){
  2022.           for(i=0; i < user_len; i++){
  2023.             for(j=0; j < user_len; j++)
  2024.               if(!strucmp(var->user_val.l[i], var->fixed_val.l[j]))
  2025.             break;
  2026.               
  2027.             if(j == user_len){
  2028.               ps_global->give_fixed_warning = 1;
  2029.               ps_global->fix_fixed_warning = 1;
  2030.               break;
  2031.             }
  2032.           }
  2033.         }
  2034.         else{
  2035.             ps_global->give_fixed_warning = 1;
  2036.             ps_global->fix_fixed_warning = 1;
  2037.         }
  2038.         }
  2039.         else if(var->fixed_val.p && !var->user_val.p
  2040.             || !var->fixed_val.p && var->user_val.p
  2041.             || (var->fixed_val.p && var->user_val.p
  2042.                 && strucmp(var->fixed_val.p, var->user_val.p))){
  2043.         ps_global->give_fixed_warning = 1;
  2044.         ps_global->fix_fixed_warning = 1;
  2045.         }
  2046.     }
  2047.  
  2048.     if(is_set[1]){
  2049.         if(var->is_list){
  2050.         /* If same length and same contents, don't warn. */
  2051.         for(list=var->fixed_val.l; list && *list; list++)
  2052.           ;/* just counting */
  2053.  
  2054.         fixed_len = var->fixed_val.l ? (list - var->fixed_val.l) : 0;
  2055.         for(list=var->cmdline_val.l; list && *list; list++)
  2056.           ;/* just counting */
  2057.  
  2058.         user_len = var->cmdline_val.l ? (list - var->cmdline_val.l) : 0;
  2059.         if(user_len == fixed_len){
  2060.           for(i=0; i < user_len; i++){
  2061.             for(j=0; j < user_len; j++)
  2062.               if(!strucmp(var->cmdline_val.l[i], var->fixed_val.l[j]))
  2063.             break;
  2064.               
  2065.             if(j == user_len){
  2066.               ps_global->give_fixed_warning = 1;
  2067.               break;
  2068.             }
  2069.           }
  2070.         }
  2071.         else{
  2072.             ps_global->give_fixed_warning = 1;
  2073.         }
  2074.         }
  2075.         else if(var->fixed_val.p && !var->cmdline_val.p
  2076.             || !var->fixed_val.p && var->cmdline_val.p
  2077.             || (var->fixed_val.p && var->cmdline_val.p
  2078.                 && strucmp(var->fixed_val.p, var->cmdline_val.p))){
  2079.         ps_global->give_fixed_warning = 1;
  2080.         }
  2081.     }
  2082.     }
  2083. }
  2084.  
  2085.  
  2086. /*
  2087.  * Feature-list has to be handled separately from the other variables
  2088.  * because it is additive.  The other variables choose one of command line,
  2089.  * or pine.conf, or pinerc.  Feature list adds them.  This could easily be
  2090.  * converted to a general purpose routine if we add more additive variables.
  2091.  *
  2092.  * This works by replacing earlier values with later ones.  That is, command
  2093.  * line settings have higher precedence than global settings and that is
  2094.  * accomplished by putting the command line features after the global
  2095.  * features in the list.  When they are processed, the last one wins.
  2096.  *
  2097.  * Feature-list also has a backwards compatibility hack.
  2098.  */
  2099. void    
  2100. set_feature_list_current_val(var)
  2101.   struct variable *var;
  2102. {
  2103.     char **list;
  2104.     char **list_fixed;
  2105.     int    i, j, k,
  2106.        elems = 0;
  2107.  
  2108.     /* count the lists so I can allocate */
  2109.     if(list=var->global_val.l)
  2110.       for(i = 0; list[i]; i++)
  2111.         elems++;
  2112.     if(list=var->user_val.l)
  2113.       for(i = 0; list[i]; i++)
  2114.         elems++;
  2115.     if(list=var->cmdline_val.l)
  2116.       for(i = 0; list[i]; i++)
  2117.         elems++;
  2118.     if(list=ps_global->feat_list_back_compat)
  2119.       for(i = 0; list[i]; i++)
  2120.         elems++;
  2121.     if(list=var->fixed_val.l)
  2122.       for(i = 0; list[i]; i++)
  2123.         elems++;
  2124.  
  2125.     list_fixed = var->fixed_val.l;
  2126.  
  2127.     var->current_val.l = (char **)fs_get((elems+1) * sizeof(char *));
  2128.  
  2129.     j = 0;
  2130.     if(list=var->global_val.l)
  2131.       for(i = 0; list[i]; i++)
  2132.         var->current_val.l[j++] = cpystr(list[i]);
  2133.     /*
  2134.      * We need to warn the user if the sys mgr has restricted him or her
  2135.      * from changing a feature that he or she is trying to change.
  2136.      *
  2137.      * I'm not catching the old-growth macro since I'm just comparing
  2138.      * strings.  That is, it works correctly, but the user won't be warned
  2139.      * if the user old-growth and the mgr says no-quit-without-confirm.
  2140.      */
  2141.     if(list=var->user_val.l)
  2142.       for(i = 0; list[i]; i++){
  2143.         var->current_val.l[j++] = cpystr(list[i]);
  2144.         for(k = 0; list_fixed && list_fixed[k]; k++){
  2145.       char *p, *q;
  2146.       p = list[i];
  2147.       q = list_fixed[k];
  2148.       if(!struncmp(p, "no-", 3))
  2149.         p += 3;
  2150.       if(!struncmp(q, "no-", 3))
  2151.         q += 3;
  2152.       if(!strucmp(q, p) && strucmp(list[i], list_fixed[k])){
  2153.           ps_global->give_fixed_warning = 1;
  2154.           ps_global->fix_fixed_warning = 1;
  2155.       }
  2156.     }
  2157.       }
  2158.     if(list=var->cmdline_val.l)
  2159.       for(i = 0; list[i]; i++){
  2160.         var->current_val.l[j++] = cpystr(list[i]);
  2161.         for(k = 0; list_fixed && list_fixed[k]; k++){
  2162.       char *p, *q;
  2163.       p = list[i];
  2164.       q = list_fixed[k];
  2165.       if(!struncmp(p, "no-", 3))
  2166.         p += 3;
  2167.       if(!struncmp(q, "no-", 3))
  2168.         q += 3;
  2169.       if(!strucmp(q, p) && strucmp(list[i], list_fixed[k]))
  2170.         ps_global->give_fixed_warning = 1;
  2171.     }
  2172.       }
  2173.     if(list=var->fixed_val.l)
  2174.       for(i = 0; list[i]; i++)
  2175.         var->current_val.l[j++] = cpystr(list[i]);
  2176.     if(list=ps_global->feat_list_back_compat)
  2177.       for(i = 0; list[i]; i++)
  2178.         var->current_val.l[j++] = cpystr(list[i]);
  2179.  
  2180.     var->current_val.l[j] = NULL;
  2181. }
  2182.                                                      
  2183.  
  2184.  
  2185. /*----------------------------------------------------------------------
  2186.  
  2187.     Expand Metacharacters/variables in file-names
  2188.  
  2189.    Read input line and expand shell-variables/meta-characters
  2190.  
  2191.     <input>        <replaced by>
  2192.     ${variable}    getenv("variable")
  2193.     $variable    getenv("variable")
  2194.     ~        getenv("HOME")
  2195.     \c        c
  2196.     <others>    <just copied>
  2197.  
  2198. NOTE handling of braces in ${name} doesn't check much or do error recovery
  2199.     
  2200.   ----*/
  2201.  
  2202. char *
  2203. expand_variables(lineout, linein)
  2204. char *linein, *lineout;
  2205. {
  2206.     char *src = linein, *dest = lineout, *p;
  2207.     int  envexpand = 0;
  2208.  
  2209.     if(!linein)
  2210.       return(NULL);
  2211.  
  2212.     while( *src ){            /* something in input string */
  2213. #if defined(DOS) || defined(OS2)
  2214.         if(*src == '$' && *(src+1) == '$'){
  2215.         /*
  2216.          * backslash to escape chars we're interested in, else
  2217.          * it's up to the user of the variable to handle the 
  2218.          * backslash...
  2219.          */
  2220.             *dest++ = *++src;        /* copy next as is */
  2221.         }else
  2222. #else
  2223.         if(*src == '\\' && *(src+1) == '$'){
  2224.         /*
  2225.          * backslash to escape chars we're interested in, else
  2226.          * it's up to the user of the variable to handle the 
  2227.          * backslash...
  2228.          */
  2229.             *dest++ = *++src;        /* copy next as is */
  2230.         }else if(*src == '~' && src == linein){
  2231.         char buf[MAXPATH];
  2232.         int  i;
  2233.  
  2234.         for(i = 0; src[i] && src[i] != '/'; i++)
  2235.           buf[i] = src[i];
  2236.  
  2237.         src    += i;        /* advance src pointer */
  2238.         buf[i]  = '\0';        /* tie off buf string */
  2239.         fnexpand(buf, MAXPATH);    /* expand the path */
  2240.  
  2241.         for(p = buf; *dest = *p; p++, dest++)
  2242.           ;
  2243.  
  2244.         continue;
  2245.         }else
  2246. #endif
  2247.     if(*src == '$'){        /* shell variable */
  2248.         char word[128];
  2249.         int  found_brace = 0;
  2250.  
  2251.         envexpand++;        /* signal that we've expanded a var */
  2252.         src++;            /* skip dollar */
  2253.         p = word;
  2254.         if(*src == '{'){        /* starts with brace? */
  2255.         src++;        
  2256.         found_brace = 1;
  2257.         }
  2258.  
  2259.         while(*src && !isspace(*src) && (!found_brace || *src != '}'))
  2260.           *p++ = *src++;        /* copy to word */
  2261.  
  2262.         if(found_brace){    /* look for closing  brace */
  2263.         while(*src && *src != '}')
  2264.           src++;        /* skip until brace */
  2265.  
  2266.         if(*src == '}')    /* skip brace */
  2267.           src++;
  2268.         }
  2269.  
  2270.         *p = '\0';            /* tie off word */
  2271.  
  2272.         if(p = getenv(word))     /* check for word in environment */
  2273.           while(*p)
  2274.         *dest++ = *p++;
  2275.  
  2276.         continue;
  2277.     }else{                /* other cases: just copy */
  2278.         *dest++ = *src;
  2279.     }
  2280.  
  2281.         if(*src)            /* next character (if any) */
  2282.       src++;
  2283.     }
  2284.  
  2285.     *dest = '\0';
  2286.     return((envexpand && lineout[0] == '\0') ? NULL : lineout);
  2287. }
  2288.  
  2289.  
  2290. /*----------------------------------------------------------------------
  2291.     Sets  login, full_username and home_dir
  2292.  
  2293.    Args: ps -- The Pine structure to put the user name, etc in
  2294.  
  2295.   Result: sets the fullname, login and home_dir field of the pine structure
  2296.           returns 0 on success, -1 if not.
  2297.   ----*/
  2298. #define    MAX_INIT_ERRS    5
  2299. void
  2300. init_error(ps, s)
  2301.     struct pine *ps;
  2302.     char    *s;
  2303. {
  2304.     int    i;
  2305.  
  2306.     if(!ps->init_errs){
  2307.     ps->init_errs = (char **)fs_get((MAX_INIT_ERRS + 1) * sizeof(char *));
  2308.     memset(ps->init_errs, 0, (MAX_INIT_ERRS + 1) * sizeof(char *));
  2309.     }
  2310.  
  2311.     for(i = 0; i < MAX_INIT_ERRS; i++)
  2312.       if(!ps->init_errs[i]){
  2313.       ps->init_errs[i] = cpystr(s);
  2314.       dprint(2, (debugfile, "%s\n", s));
  2315.       break;
  2316.       }
  2317. }
  2318.  
  2319.  
  2320. /*----------------------------------------------------------------------
  2321.     Sets  login, full_username and home_dir
  2322.  
  2323.    Args: ps -- The Pine structure to put the user name, etc in
  2324.  
  2325.   Result: sets the fullname, login and home_dir field of the pine structure
  2326.           returns 0 on success, -1 if not.
  2327.   ----*/
  2328.  
  2329. init_username(ps)
  2330.      struct pine *ps;
  2331. {
  2332.     char fld_dir[MAXPATH+1], *expanded;
  2333.     int  rv;
  2334.  
  2335.     rv       = 0;
  2336.     expanded = NULL;
  2337. #if defined(DOS) || defined(OS2)
  2338.     if(ps->COM_USER_ID)
  2339.       expanded = expand_variables(tmp_20k_buf,
  2340.                   ps->COM_USER_ID);
  2341.     
  2342.     if(!expanded && ps->USR_USER_ID)
  2343.       expanded = expand_variables(tmp_20k_buf, ps->USR_USER_ID);
  2344.  
  2345.     if(!expanded)
  2346.       ps->blank_user_id = 1;
  2347.  
  2348.     ps->VAR_USER_ID = cpystr(expanded ? expanded : "");
  2349. #else
  2350.     ps->VAR_USER_ID = cpystr(ps->ui.login);
  2351.     if(!ps->VAR_USER_ID[0]){
  2352.         fprintf(stderr, "Who are you? (Unable to look up login name)\n");
  2353.         rv = -1;
  2354.     }
  2355. #endif
  2356.  
  2357.     expanded = NULL;
  2358.     if(ps->vars[V_PERSONAL_NAME].is_fixed){
  2359.     if(ps->FIX_PERSONAL_NAME){
  2360.             expanded = expand_variables(tmp_20k_buf, ps->FIX_PERSONAL_NAME);
  2361.     }
  2362.     if(ps->USR_PERSONAL_NAME){
  2363.         ps_global->give_fixed_warning = 1;
  2364.         ps_global->fix_fixed_warning = 1;
  2365.     }
  2366.     else if(ps->COM_PERSONAL_NAME)
  2367.       ps_global->give_fixed_warning = 1;
  2368.     }
  2369.     else{
  2370.     if(ps->COM_PERSONAL_NAME)
  2371.       expanded = expand_variables(tmp_20k_buf,
  2372.                 ps->COM_PERSONAL_NAME);
  2373.  
  2374.     if(!expanded && ps->USR_PERSONAL_NAME)
  2375.       expanded = expand_variables(tmp_20k_buf,
  2376.                       ps->USR_PERSONAL_NAME);
  2377.     }
  2378.  
  2379.     if(!expanded){
  2380.     expanded = ps->ui.fullname;
  2381. #if defined(DOS) || defined(OS2)
  2382.     ps->blank_personal_name = 1;
  2383. #endif
  2384.     }
  2385.  
  2386.     ps->VAR_PERSONAL_NAME = cpystr(expanded ? expanded : "");
  2387.  
  2388.     if(strlen(ps->home_dir) + strlen(ps->VAR_MAIL_DIRECTORY)+2 > MAXPATH){
  2389.         printf("Folders directory name is longer than %d\n", MAXPATH);
  2390.         printf("Directory name: \"%s/%s\"\n",ps->home_dir,
  2391.                ps->VAR_MAIL_DIRECTORY);
  2392.         return(-1);
  2393.     }
  2394. #if defined(DOS) || defined(OS2)
  2395.     if(ps->VAR_MAIL_DIRECTORY[1] == ':')
  2396.       strcpy(fld_dir, ps->VAR_MAIL_DIRECTORY);
  2397.     else
  2398. #endif
  2399.     build_path(fld_dir, ps->home_dir, ps->VAR_MAIL_DIRECTORY);
  2400.     ps->folders_dir = cpystr(fld_dir);
  2401.  
  2402.     dprint(1, (debugfile, "Userid: %s\nFullname: \"%s\"\n",
  2403.                ps->VAR_USER_ID, ps->VAR_PERSONAL_NAME));
  2404.     return(rv);
  2405. }
  2406.  
  2407.  
  2408. /*----------------------------------------------------------------------
  2409.         Fetch the hostname of the current system and put it in pine struct
  2410.  
  2411.    Args: ps -- The pine structure to put the hostname, etc in
  2412.  
  2413.   Result: hostname, localdomain, userdomain and maildomain are set
  2414.  
  2415.  
  2416. ** Pine uses the following set of names:
  2417.   hostname -    The fully-qualified hostname.  Obtained with
  2418.         gethostbyname() which reads /etc/hosts or does a DNS
  2419.         lookup.  This may be blank.
  2420.   localdomain - The domain name without the host.  Obtained from the
  2421.         above hostname if it has a "." in it.  Removes first
  2422.         segment.  If hostname has no "." in it then the hostname
  2423.         is used.  This may be blank.
  2424.   userdomain -  Explicitly configured domainname.  This is read out of the
  2425.         global pine.conf or user's .pinerc.  The user's entry in the
  2426.         .pinerc overrides.
  2427.  
  2428. ** Pine has the following uses for such names:
  2429.  
  2430.   1. On outgoing messages in the From: line
  2431.     Uses userdomain if there is one.  If not uses, uses
  2432.     hostname unless Pine has been configured to use localdomain.
  2433.  
  2434.   2. When expanding/fully-qualifying unqualified addresses during
  2435.      composition
  2436.     (same as 1)
  2437.  
  2438.   3. When expanding/fully-qualifying unqualified addresses during
  2439.      composition when a local entry in the password file exists for
  2440.      name.
  2441.         If no userdomain is given, then this lookup is always done
  2442.     and the hostname is used unless Pine's been configured to 
  2443.     use the localdomain.  If userdomain is defined, it is used,
  2444.     but no local lookup is done.  We can't assume users on the
  2445.     local host are valid in the given domain (and, for simplicity,
  2446.     have chosen to ignore the cases userdomain matches localdomain
  2447.     or localhost).  Setting user-lookup-even-if-domain-mismatch
  2448.     feature will tell pine to override this behavior and perform
  2449.     the local lookup anyway.  The problem of a global "even-if"
  2450.     set and a .pinerc-defined user-domain of something odd causing
  2451.     the local lookup, but this will only effect the personal name, 
  2452.     and is not judged to be a significant problem.
  2453.  
  2454.   4. In determining if an address is that of the current pine user for
  2455.      formatting index and filtering addresses when replying
  2456.     If a userdomain is specified the address must match the
  2457.     userdomain exactly.  If a userdomain is not specified or the
  2458.     userdomain is the same as the hostname or domainname, then
  2459.     an address will be considered the users if it matches either
  2460.     the domainname or the hostname.  Of course, the userid must
  2461.     match too. 
  2462.  
  2463.   5. In Message ID's
  2464.     The fully-qualified hostname is always users here.
  2465.  
  2466.  
  2467. ** Setting the domain names
  2468.   To set the domain name for all Pine users on the system to be
  2469. different from what Pine figures out from DNS, set the domain name in
  2470. the "user-domain" variable in pine.conf.  To set the domain name for an
  2471. individual user, set the "user-domain" variable in his .pinerc.
  2472. The .pinerc setting overrides any other setting.
  2473.  ----*/
  2474. init_hostname(ps)
  2475.      struct pine *ps;
  2476. {
  2477.     char hostname[MAX_ADDRESS+1], domainname[MAX_ADDRESS+1];
  2478.  
  2479.     getdomainnames(hostname, MAX_ADDRESS, domainname, MAX_ADDRESS);
  2480.  
  2481.     if(ps->hostname)
  2482.       fs_give((void **)&ps->hostname);
  2483.  
  2484.     ps->hostname = cpystr(hostname);
  2485.  
  2486.     if(ps->localdomain)
  2487.       fs_give((void **)&ps->localdomain);
  2488.  
  2489.     ps->localdomain = cpystr(domainname);
  2490.     ps->userdomain  = NULL;
  2491.  
  2492.     if(ps->VAR_USER_DOMAIN && ps->VAR_USER_DOMAIN[0]){
  2493.         ps->maildomain = ps->userdomain = ps->VAR_USER_DOMAIN;
  2494.     }else{
  2495. #if defined(DOS) || defined(OS2)
  2496.     if(ps->VAR_USER_DOMAIN)
  2497.       ps->blank_user_domain = 1;    /* user domain set to null string! */
  2498.  
  2499.         ps->maildomain = ps->localdomain[0] ? ps->localdomain : ps->hostname;
  2500. #else
  2501.         ps->maildomain = strucmp(ps->VAR_USE_ONLY_DOMAIN_NAME, "yes")
  2502.               ? ps->hostname : ps->localdomain;
  2503. #endif
  2504.     }
  2505.  
  2506.     /*
  2507.      * Tell c-client what domain to use when completing unqualified
  2508.      * addresses it finds in local mailboxes.  Remember, it won't 
  2509.      * affect what's to the right of '@' for unqualified addresses in
  2510.      * remote folders...
  2511.      */
  2512.     mail_parameters(NULL, SET_LOCALHOST, (void *) ps->maildomain);
  2513.     if(!strchr(ps->maildomain, '.')){
  2514.     sprintf(tmp_20k_buf, "Incomplete maildomain \"%s\".",
  2515.         ps->maildomain);
  2516.     init_error(ps, tmp_20k_buf);
  2517.     strcpy(tmp_20k_buf,
  2518.            "Return address in mail you send may be incorrect.");
  2519.     init_error(ps, tmp_20k_buf);
  2520.     }
  2521.  
  2522.     dprint(1, (debugfile,"User domain name being used \"%s\"\n",
  2523.                ps->userdomain == NULL ? "" : ps->userdomain));
  2524.     dprint(1, (debugfile,"Local Domain name being used \"%s\"\n",
  2525.                ps->localdomain));
  2526.     dprint(1, (debugfile,"Host name being used \"%s\"\n",
  2527.                ps->hostname));
  2528.     dprint(1, (debugfile,
  2529.            "Mail Domain name being used (by c-client too)\"%s\"\n",
  2530.                ps->maildomain));
  2531.  
  2532.     if(!ps->maildomain || !ps->maildomain[0]){
  2533. #if defined(DOS) || defined(OS2)
  2534.     if(ps->blank_user_domain)
  2535.       return(0);        /* prompt for this in send.c:dos_valid_from */
  2536. #endif
  2537.         fprintf(stderr, "No host name or domain name set\n");
  2538.         return(-1);
  2539.     }
  2540.     else
  2541.       return(0);
  2542. }
  2543.  
  2544.  
  2545. /*----------------------------------------------------------------------
  2546.          Read and parse a pinerc file
  2547.   
  2548.    Args:  Filename   -- name of the .pinerc file to open and read
  2549.           vars       -- The vars structure to store values in
  2550.           which_vars -- Whether the local or global values are being read
  2551.  
  2552.    Result: 
  2553.  
  2554.  This may be the local file or the global file.  The values found are
  2555. merged with the values currently in vars.  All values are strings and
  2556. are malloced; and existing values will be freed before the assignment.
  2557. Those that are <unset> will be left unset; their values will be NULL.
  2558.   ----*/
  2559. void
  2560. read_pinerc(filename, vars, which_vars)
  2561.      char *filename;
  2562.      ParsePinerc which_vars;
  2563.      struct variable *vars;
  2564. {
  2565.     char               *file, *value, **lvalue, *line, *error;
  2566.     register char      *p, *p1;
  2567.     struct variable    *v;
  2568.     struct pinerc_line *pline;
  2569.     int                 line_count, was_quoted;
  2570.     int            i;
  2571.  
  2572.     dprint(1, (debugfile, "reading_pinerc \"%s\"\n", filename));
  2573.  
  2574.     file = read_file(filename);
  2575.     if(file == NULL){
  2576.         dprint(1, (debugfile, "Open failed: %s\n", error_description(errno)));
  2577.     if(which_vars == ParseLocal)
  2578.         ps_global->first_time_user = 1;
  2579.         return;
  2580.     }
  2581.     else{
  2582.     /*
  2583.      * fixup unix newlines?  note: this isn't a problem under dos
  2584.      * since the file's read in text mode.
  2585.      */
  2586.     for(p = file; *p && *p != '\012'; p++)
  2587.       ;
  2588.  
  2589.     if(p > file && *p && *(p-1) == '\015')    /* cvt crlf to lf */
  2590.       for(p1 = p - 1; *p1 = *p; p++)
  2591.         if(!(*p == '\015' && *(p+1) == '\012'))
  2592.           p1++;
  2593.     }
  2594.  
  2595.     dprint(1, (debugfile, "Read %d characters:\n", strlen(file)));
  2596.  
  2597.     if(which_vars == ParseLocal){
  2598.       /*--- Count up lines and allocate structures */
  2599.       for(line_count = 0, p = file; *p != '\0'; p++)
  2600.         if(*p == '\n')
  2601.       line_count++;
  2602.       pinerc_lines = (struct pinerc_line *)
  2603.                fs_get((3 + line_count) * sizeof(struct pinerc_line));
  2604.       memset((void *)pinerc_lines, 0,
  2605.                 (3 + line_count) * sizeof(struct pinerc_line));
  2606.       pline = pinerc_lines;
  2607.  
  2608.       /* copyright stuff, sorry, magic numbers galore */
  2609.       p = file;
  2610.       if(which_vars == ParseLocal){
  2611.         if(strncmp(p, cf_text_comment1, strlen(cf_text_comment1)) == 0){
  2612.       /* find the comma after the version number */
  2613.       p = strchr(p+strlen(cf_text_comment1), ',');
  2614.           if(p && strncmp(p, cf_text_comment2, 11) == 0){
  2615.             p += strlen(cf_text_comment2) - 26;
  2616.             if(p &&
  2617.          strncmp(p, cf_text_comment2+strlen(cf_text_comment2)-26,26) == 0){
  2618.            copyright_line_is_there = 1;
  2619.         }
  2620.       }
  2621.         }
  2622.         p = strchr(p, '\n');
  2623.         if(p && *(p+1) && strncmp(p+1, cf_text_comment3, 27) == 0)
  2624.           trademark_lines_are_there = 1;
  2625.       }
  2626.     }
  2627.  
  2628.     for(p = file, line = file; *p != '\0';){
  2629.         /*----- Grab the line ----*/
  2630.         line = p;
  2631.         while(*p && *p != '\n')
  2632.           p++;
  2633.         if(*p == '\n'){
  2634.             *p++ = '\0';
  2635.         }
  2636.  
  2637.         /*----- Comment Line -----*/
  2638.         if(*line == '#'){
  2639.             if(which_vars == ParseLocal){
  2640.                 pline->is_var = 0;
  2641.                 pline->line = cpystr(line);
  2642.                 pline++;
  2643.             }
  2644.             continue;
  2645.         }
  2646.  
  2647.     if(*line == '\0' || *line == '\t' || *line == ' '){
  2648.             p1 = line;
  2649.             while(*p1 == '\t' || *p1 == ' ')
  2650.                p1++;
  2651.             if(which_vars == ParseLocal){
  2652.             if(*p1 != '\0') /* contin. line from some future version? */
  2653.                     pline->line = cpystr(line);
  2654.             else
  2655.                     pline->line = cpystr("");
  2656.                pline->is_var = 0;
  2657.                pline++;
  2658.             }
  2659.             continue;
  2660.     }
  2661.  
  2662.         /*----- look up matching 'v' and leave "value" after '=' ----*/
  2663.         for(v = vars; *line && v->name; v++)
  2664.       if((i = strlen(v->name)) < strlen(line) && !strncmp(v->name,line,i)){
  2665.           int j;
  2666.  
  2667.           for(j = i; line[j] == ' ' || line[j] == '\t'; j++)
  2668.         ;
  2669.  
  2670.           if(line[j] == '='){    /* bingo! */
  2671.           for(value = &line[j+1];
  2672.               *value == ' ' || *value == '\t';
  2673.               value++)
  2674.             ;
  2675.  
  2676.           break;
  2677.           }
  2678.           /* else either unrecognized var or bogus line */
  2679.       }
  2680.  
  2681.         /*----- Didn't match any variable or bogus format -----*/
  2682.         if(!v->name){
  2683.             if(which_vars == ParseLocal){
  2684.                 pline->is_var = 0;
  2685.                 pline->line = cpystr(line);
  2686.                 pline++;
  2687.             }
  2688.             continue;
  2689.         }
  2690.  
  2691.         /*----- Obsolete variable, read it anyway below, might use it -----*/
  2692.         if(v->is_obsolete){
  2693.             if(which_vars == ParseLocal){
  2694.                 pline->obsolete_var = 1;
  2695.                 pline->line = cpystr(line);
  2696.                 pline->var = v;
  2697.             }
  2698.         }
  2699.  
  2700.         /*----- Variable is in the list but unused for some reason -----*/
  2701.         if(!v->is_used){
  2702.             if(which_vars == ParseLocal){
  2703.                 pline->is_var = 0;
  2704.                 pline->line = cpystr(line);
  2705.                 pline++;
  2706.             }
  2707.             continue;
  2708.         }
  2709.  
  2710.         /*--- Var is not user controlled, leave it alone for back compat ---*/
  2711.         if(!v->is_user && which_vars == ParseLocal){
  2712.         pline->is_var = 0;
  2713.         pline->line = cpystr(line);
  2714.         pline++;
  2715.         continue;
  2716.         }
  2717.  
  2718.     if(which_vars == ParseFixed)
  2719.         v->is_fixed = 1;
  2720.  
  2721.         /*---- variable is unset ----*/
  2722.         if(!*value){
  2723.             if(v->is_user && which_vars == ParseLocal){
  2724.                 pline->is_var   = 1;
  2725.                 pline->var = v;
  2726.                 pline++;
  2727.             }
  2728.             continue;
  2729.         }
  2730.  
  2731.         /*--value is non-empty, store it handling quotes and trailing space--*/
  2732.         if(*value == '"' && !v->is_list){
  2733.             was_quoted = 1;
  2734.             value++;
  2735.             for(p1 = value; *p1 && *p1 != '"'; p1++);
  2736.             if(*p1 == '"')
  2737.               *p1 = '\0';
  2738.             else
  2739.               removing_trailing_white_space(value);
  2740.         }else{
  2741.             removing_trailing_white_space(value);
  2742.             was_quoted = 0;
  2743.         }
  2744.  
  2745.     /*
  2746.      * List Entry Parsing
  2747.      *
  2748.      * The idea is to parse a comma separated list of 
  2749.      * elements, preserving quotes, and understanding
  2750.      * continuation lines (that is ',' == "\n ").
  2751.      * Quotes must be balanced within elements.  Space 
  2752.      * within elements is preserved, but leading and trailing 
  2753.      * space is trimmed.  This is a generic function, and it's 
  2754.      * left to the the functions that use the lists to make sure
  2755.      * they contain valid data...
  2756.      */
  2757.     if(v->is_list){
  2758.  
  2759.         was_quoted = 0;
  2760.         line_count = 0;
  2761.         p1         = value;
  2762.         while(1){            /* generous count of list elements */
  2763.         if(*p1 == '"')        /* ignore ',' if quoted   */
  2764.           was_quoted = (was_quoted) ? 0 : 1 ;
  2765.  
  2766.         if((*p1 == ',' && !was_quoted) || *p1 == '\n' || *p1 == '\0')
  2767.           line_count++;        /* count this element */
  2768.  
  2769.         if(*p1 == '\0' || *p1 == '\n'){    /* deal with EOL */
  2770.             if(p1 < p || *p1 == '\n'){
  2771.             *p1++ = ',';     /* fix null or newline */
  2772.  
  2773.             if(*p1 != '\t' && *p1 != ' '){
  2774.                 *(p1-1) = '\0'; /* tie off list */
  2775.                 p       = p1;   /* reset p */
  2776.                 break;
  2777.             }
  2778.             }else{
  2779.             p = p1;        /* end of pinerc */
  2780.             break;
  2781.             }
  2782.         }else
  2783.           p1++;
  2784.         }
  2785.  
  2786.         error  = NULL;
  2787.         lvalue = parse_list(value, line_count, &error);
  2788.         if(error){
  2789.         dprint(1, (debugfile,
  2790.                "read_pinerc: ERROR: %s in %s = \"%s\"\n", 
  2791.                error, v->name, value));
  2792.         }
  2793.         /*
  2794.          * Special case: turn "" strings into empty strings.
  2795.          * This allows users to turn off default lists.  For example,
  2796.          * if smtp-server is set then a user could override smtp-server
  2797.          * with smtp-server="".
  2798.          */
  2799.         for(i = 0; lvalue[i]; i++)
  2800.         if(lvalue[i][0] == '"' &&
  2801.            lvalue[i][1] == '"' &&
  2802.            lvalue[i][2] == '\0')
  2803.              lvalue[i][0] = '\0';
  2804.     }
  2805.  
  2806.         if(which_vars == ParseLocal){
  2807.             if(v->is_user){
  2808.         if(v->is_list){
  2809.             if(v->user_val.l){
  2810.             char **p;
  2811.             for(p = v->user_val.l; *p ; p++)
  2812.               fs_give((void **)p);
  2813.  
  2814.             fs_give((void **)&(v->user_val.l));
  2815.             }
  2816.  
  2817.             v->user_val.l = lvalue;
  2818.         }else{
  2819.             if(v->user_val.p != NULL)
  2820.               fs_give((void **) &(v->user_val.p));
  2821.  
  2822.             v->user_val.p = cpystr(value);
  2823.  
  2824.         }
  2825.  
  2826.         pline->is_var    = 1;
  2827.         pline->var  = v;
  2828.         pline->is_quoted = was_quoted;
  2829.         pline++;
  2830.             }
  2831.         }else if(which_vars == ParseGlobal){
  2832.             if(v->is_global){
  2833.         if(v->is_list){
  2834.             if(v->global_val.l){
  2835.             char **p;
  2836.             for(p = v->global_val.l; *p ; p++)
  2837.               fs_give((void **)p);
  2838.  
  2839.             fs_give((void **)&(v->global_val.l));
  2840.             }
  2841.  
  2842.             v->global_val.l = lvalue;
  2843.         }else{
  2844.             if(v->global_val.p != NULL)
  2845.               fs_give((void **) &(v->global_val.p));
  2846.             v->global_val.p = cpystr(value);
  2847.         }
  2848.             }
  2849.         }else{  /* which_vars == ParseFixed */
  2850.             if(v->is_user || v->is_global){
  2851.         if(v->is_list){
  2852.             if(v->fixed_val.l){
  2853.             char **p;
  2854.             for(p = v->fixed_val.l; *p ; p++)
  2855.               fs_give((void **)p);
  2856.  
  2857.             fs_give((void **)&(v->fixed_val.l));
  2858.             }
  2859.  
  2860.             v->fixed_val.l = lvalue;
  2861.         }else{
  2862.             if(v->fixed_val.p != NULL)
  2863.               fs_give((void **) &(v->fixed_val.p));
  2864.             v->fixed_val.p = cpystr(value);
  2865.         }
  2866.         }
  2867.     }
  2868.  
  2869. #ifdef DEBUG
  2870.     if(v->is_list){
  2871.         char **t;
  2872.         t =   which_vars == ParseLocal  ? v->user_val.l
  2873.             : which_vars == ParseGlobal ? v->global_val.l
  2874.         :                             v->fixed_val.l;
  2875.         if(t && *t && **t){
  2876.                 dprint(3,(debugfile, " %20.20s : %s\n", v->name, *t));
  2877.             while(++t && *t && **t)
  2878.                     dprint(3,(debugfile, " %20.20s : %s\n", "", *t));
  2879.         }
  2880.     }else{
  2881.         char *t;
  2882.         t =   which_vars == ParseLocal  ? v->user_val.p
  2883.             : which_vars == ParseGlobal ? v->global_val.p
  2884.         :                             v->fixed_val.p;
  2885.         if(t && *t)
  2886.                 dprint(3,(debugfile, " %20.20s : %s\n", v->name, t));
  2887.     }
  2888. #endif /* DEBUG */
  2889.     }
  2890.     if(which_vars == ParseLocal){
  2891.         pline->line = NULL;
  2892.         pline->is_var = 0;
  2893.     }
  2894.     fs_give((void **)&file);
  2895. }
  2896.  
  2897.  
  2898. /*
  2899.  * parse_list - takes a comma delimited list of "count" elements and 
  2900.  *              returns an array of pointers to each element neatly
  2901.  *              malloc'd in its own array.  Any errors are returned
  2902.  *              in the string pointed to by "error"
  2903.  *
  2904.  *  NOTE: only recognizes escaped quotes
  2905.  */
  2906. char **
  2907. parse_list(list, count, error)
  2908.     char *list, **error;
  2909.     int   count;
  2910. {
  2911.     char **lvalue, *p2, *p3, *p4;
  2912.     int    was_quoted = 0;
  2913.  
  2914.     lvalue = (char **)fs_get((count+1)*sizeof(char *));
  2915.     count  = 0;
  2916.     while(*list){            /* pick elements from list */
  2917.     p2 = list;        /* find end of element */
  2918.     while(1){
  2919.         if(*p2 == '"')    /* ignore ',' if quoted   */
  2920.           was_quoted = (was_quoted) ? 0 : 1 ;
  2921.  
  2922.         if(*p2 == '\\' && *(p2+1) == '"')
  2923.           p2++;        /* preserve escaped quotes, too */
  2924.  
  2925.         if((*p2 == ',' && !was_quoted) || *p2 == '\0')
  2926.           break;
  2927.  
  2928.         p2++;
  2929.     }
  2930.  
  2931.     if(was_quoted){        /* unbalanced parens! */
  2932.         if(error)
  2933.           *error = "Unbalanced parentheses";
  2934.  
  2935.         break;
  2936.     }
  2937.  
  2938.     /*
  2939.      * if element found, eliminate trailing 
  2940.      * white space and tie into variable list
  2941.      */
  2942.     if(p2 != list){
  2943.         for(p3 = p2 - 1; isspace(*p3) && list < p3; p3--)
  2944.           ;
  2945.  
  2946.         p4 = fs_get(((p3 - list) + 2) * sizeof(char));
  2947.         lvalue[count++] = p4;
  2948.         while(list <= p3)
  2949.           *p4++ = *list++;
  2950.  
  2951.         *p4 = '\0';
  2952.     }
  2953.  
  2954.     if(*(list = p2) != '\0'){    /* move to beginning of next val */
  2955.         while(*list == ',' || isspace(*list))
  2956.           list++;
  2957.     }
  2958.     }
  2959.  
  2960.     lvalue[count] = NULL;        /* tie off pointer list */
  2961.     return(lvalue);
  2962. }
  2963.  
  2964.  
  2965. static char quotes[3] = {'"', '"', '\0'};
  2966. /*----------------------------------------------------------------------
  2967.     Write out the .pinerc state information
  2968.  
  2969.    Args: ps -- The pine structure to take state to be written from
  2970.  
  2971.   This writes to a temporary file first, and then renames that to 
  2972.  be the new .pinerc file to protect against disk error.  This has the 
  2973.  problem of possibly messing up file protections, ownership and links.
  2974.   ----*/
  2975. write_pinerc(ps)
  2976.     struct pine *ps;
  2977. {
  2978.     char                buf[MAXPATH+1], copyright[90], *p, *dir, *tmp;
  2979.     int            write_trademark = 0;
  2980.     FILE               *f;
  2981.     struct pinerc_line *pline;
  2982.     struct variable    *var;
  2983.  
  2984.     dprint(2,(debugfile,"---- write_pinerc ----\n"));
  2985.  
  2986.     /* don't write if pinerc is read-only */
  2987.     if(ps->readonly_pinerc ||
  2988.          (can_access(ps->pinerc, ACCESS_EXISTS) == 0 &&
  2989.           can_access(ps->pinerc, EDIT_ACCESS) != 0)){
  2990.     ps->readonly_pinerc = 1;
  2991.     dprint(2,
  2992.         (debugfile,"write_pinerc: fail because can't access pinerc\n"));
  2993.     return(-1);
  2994.     }
  2995.  
  2996.     dir = ".";
  2997.     if(p = last_cmpnt(ps->pinerc)){
  2998.     *--p = '\0';
  2999.     dir = ps->pinerc;
  3000.     }
  3001.  
  3002. #if    defined(DOS) || defined(OS2)
  3003.     if(!(isalpha(dir[0]) && dir[1] == ':' && dir[2] == '\0')
  3004.        && (can_access(dir, EDIT_ACCESS) < 0 &&
  3005. #ifdef    DOS
  3006.        mkdir(dir) < 0)){
  3007. #else
  3008.        mkdir(dir,0700) < 0)) {
  3009. #endif
  3010.     q_status_message2(SM_ORDER | SM_DING, 3, 5,
  3011.               "Error creating \"%s\" : %s", dir,
  3012.               error_description(errno));
  3013.     return(-1);
  3014.     }
  3015.  
  3016.     tmp = temp_nam(dir, "rc");
  3017.     if(p)
  3018.       *p = '\\';
  3019.  
  3020.     if(tmp == NULL)
  3021.       goto io_err;
  3022.  
  3023.     strcpy(buf, tmp);
  3024.     free(tmp);
  3025.     f = fopen(buf, "wt");
  3026. #else  /* !DOS */
  3027.     tmp = temp_nam((*dir) ? dir : "/", "pinerc");
  3028.     if(p)
  3029.       *p = '/';
  3030.  
  3031.     if(tmp == NULL)
  3032.       goto io_err;
  3033.  
  3034.     strcpy(buf, tmp);
  3035.     free(tmp);
  3036.     f = fopen(buf, "w");
  3037. #endif  /* !DOS */
  3038.  
  3039.     if(f == NULL) 
  3040.       goto io_err;
  3041.  
  3042.     for(var = ps->vars; var->name != NULL; var++) 
  3043.       var->been_written = 0;
  3044.  
  3045.     /* copyright stuff starts here */
  3046.     pline = pinerc_lines;
  3047.     if(ps->first_time_user ||
  3048.        (ps->show_new_version && !trademark_lines_are_there))
  3049.       write_trademark = 1;
  3050.  
  3051.     /* if it was already there, remove old one */
  3052.     if(copyright_line_is_there)
  3053.       pline++;
  3054.  
  3055.     if(fprintf(f, "%s%s%s", cf_text_comment1, pine_version,
  3056.            cf_text_comment2) == EOF)
  3057.       goto io_err;
  3058.     if(write_trademark && fprintf(f, "%s%s", cf_text_comment3,
  3059.                   ps->first_time_user ? "" : "\n") == EOF)
  3060.       goto io_err;
  3061.     /* end of copyright stuff */
  3062.  
  3063.     /* Write out what was in the .pinerc */
  3064.     if(pline != NULL){
  3065.     for(; pline->is_var || pline->line != NULL; pline++){
  3066.         if(pline->is_var && !pline->obsolete_var){
  3067.         var = pline->var;
  3068.         if((var->is_list && (!var->user_val.l || !var->user_val.l[0]))
  3069.            || (!var->is_list && !var->user_val.p)){
  3070.             if(fprintf(f, "%s=\n", pline->var->name) == EOF)
  3071.               goto io_err;
  3072.         }
  3073.         else if((var->is_list && *var->user_val.l[0] == '\0')
  3074.              || (!var->is_list && *var->user_val.p == '\0')){
  3075.             if(fprintf(f, "%s=%s\n", pline->var->name, quotes) == EOF)
  3076.               goto io_err;
  3077.         }
  3078.         else{
  3079.             if(var->is_list){
  3080.             int i = 0;
  3081.  
  3082.             for(i = 0; var->user_val.l[i]; i++)
  3083.               if(fprintf(f, "%s%s%s%s\n",
  3084.                      (i) ? "\t" : var->name,
  3085.                      (i) ? "" : "=",
  3086.                      var->user_val.l[i][0] 
  3087.                        ? var->user_val.l[i] : quotes,
  3088.                      var->user_val.l[i+1] ? ",":"") == EOF)
  3089.                 goto io_err;
  3090.             }
  3091.             else{
  3092.             if(fprintf(f, "%s=%s%s%s\n", pline->var->name,
  3093.                    (pline->is_quoted
  3094.                     && *pline->var->user_val.p != '\"')
  3095.                      ? "\"" : "",
  3096.                    pline->var->user_val.p,
  3097.                    (pline->is_quoted
  3098.                     && *pline->var->user_val.p != '\"')
  3099.                      ? "\"" : "") == EOF)
  3100.               goto io_err;
  3101.             }
  3102.         }
  3103.  
  3104.         pline->var->been_written = 1;
  3105.         }else{
  3106.         /*
  3107.          * The description text should be changed into a message
  3108.          * about the variable being obsolete when a variable is
  3109.          * moved to obsolete status.  We add that message before
  3110.          * the variable unless it is already there.  However, we
  3111.          * leave the variable itself in case the user runs an old
  3112.          * version of pine again.  Note that we have read in the
  3113.          * value of the variable in read_pinerc and translated it
  3114.          * into a new variable if appropriate.
  3115.          */
  3116.         if(pline->obsolete_var){
  3117.             if(pline <= pinerc_lines || (pline-1)->line == NULL ||
  3118.                strlen((pline-1)->line) < 3 ||
  3119.                strucmp((pline-1)->line+2, pline->var->descrip) != 0)
  3120.               if(fprintf(f, "# %s\n", pline->var->descrip) == EOF)
  3121.             goto io_err;
  3122.         }
  3123.  
  3124.         if(fprintf(f, "%s\n", pline->line) == EOF)
  3125.           goto io_err;
  3126.         }
  3127.     }
  3128.     }
  3129.  
  3130.     /* Now write out all the variables not in the .pinerc */
  3131.     for(var = ps->vars; var->name != NULL; var++){
  3132.     if(!var->is_user || var->been_written || !var->is_used
  3133.        || var->is_obsolete)
  3134.       continue;
  3135.  
  3136.     dprint(5,(debugfile,"write_pinerc: %s = %s\n", var->name,
  3137.           var->user_val.p ? var->user_val.p : "<not set>"));
  3138.  
  3139.     /* Add extra comments about categories of variables */
  3140.     if(ps->first_time_user){
  3141.         if(var == &variables[V_PERSONAL_NAME]){
  3142.         if(fprintf(f, "\n%s\n", cf_before_personal_name) == EOF)
  3143.           goto io_err;
  3144.         }
  3145.         else if(var == &variables[V_INCOMING_FOLDERS]){
  3146.         if(fprintf(f, "\n%s\n", cf_before_incoming_folders) == EOF)
  3147.           goto io_err;
  3148.         }
  3149.         else if(var == &variables[V_FEATURE_LIST]){
  3150.         if(fprintf(f, "\n%s\n", cf_before_feature_list) == EOF)
  3151.           goto io_err;
  3152.         }
  3153.         else if(var == &variables[V_PRINTER]){
  3154.         if(fprintf(f, "\n%s\n", cf_before_printer) == EOF)
  3155.           goto io_err;
  3156.         }
  3157.     }
  3158.  
  3159.     /*
  3160.      * set description to NULL to eliminate preceding
  3161.      * blank and comment line.
  3162.      */
  3163.     if(var->descrip && *var->descrip
  3164.        && fprintf(f, "\n# %s\n", var->descrip) == EOF)
  3165.       goto io_err;
  3166.  
  3167.     if((var->is_list && (!var->user_val.l
  3168.                  || (!var->user_val.l[0] && !var->global_val.l)))
  3169.        || (!var->is_list && !var->user_val.p)){
  3170.         if(fprintf(f, "%s=\n", var->name) == EOF)
  3171.           goto io_err;
  3172.     }
  3173.     else if((var->is_list
  3174.          && (!var->user_val.l[0] || !var->user_val.l[0][0]))
  3175.         || (!var->is_list && var->user_val.p[0] == '\0')){
  3176.         if(fprintf(f, "%s=\"\"\n", var->name) == EOF)
  3177.           goto io_err;
  3178.     }
  3179.     else if(var->is_list){
  3180.         int i = 0;
  3181.  
  3182.         for(i = 0; var->user_val.l[i] ; i++)
  3183.           if(fprintf(f, "%s%s%s%s\n", (i) ? "\t" : var->name,
  3184.              (i) ? "" : "=", var->user_val.l[i],
  3185.              var->user_val.l[i+1] ? ",":"") == EOF)
  3186.         goto io_err;
  3187.     }
  3188.     else{
  3189.         if(fprintf(f, "%s=%s\n", var->name, var->user_val.p) == EOF)
  3190.           goto io_err;
  3191.     }
  3192.     }
  3193.  
  3194.     if(fclose(f) == EOF || rename_file(buf, ps->pinerc) < 0)
  3195.       goto io_err;
  3196.  
  3197.     ps->outstanding_pinerc_changes = 0;
  3198.  
  3199.     return(0);
  3200.  
  3201.   io_err:
  3202.     q_status_message2(SM_ORDER | SM_DING, 3, 5,
  3203.               "Error saving configuration in file \"%s\": %s",
  3204.               ps->pinerc, error_description(errno));
  3205.     dprint(1, (debugfile, "Error writing %s : %s\n", ps->pinerc,
  3206.            error_description(errno)));
  3207.     return(-1);
  3208. }
  3209.  
  3210.  
  3211. /*------------------------------------------------------------
  3212.   Return TRUE if the given string was a feature name present in the
  3213.   pinerc as it was when pine was started...
  3214.   ----*/
  3215. var_in_pinerc(s)
  3216. char *s;
  3217. {
  3218.     struct pinerc_line *pline;
  3219.     for(pline = pinerc_lines; pline->var || pline->line; pline++)
  3220.       if(pline->var && pline->var->name && !strucmp(s, pline->var->name))
  3221.     return(1);
  3222.  
  3223.     return(0);
  3224. }
  3225.  
  3226.  
  3227.  
  3228. /*------------------------------------------------------------
  3229.   Free resources associated with static pinerc_lines data
  3230.  ----*/
  3231. void
  3232. free_pinerc_lines()
  3233. {
  3234.     struct pinerc_line *pline;
  3235.  
  3236.     if(pline = pinerc_lines){
  3237.     for( ; pline->var || pline->line; pline++)
  3238.       if(pline->line)
  3239.         fs_give((void **)&pline->line);
  3240.  
  3241.     fs_give((void **)&pinerc_lines);
  3242.     }
  3243. }
  3244.  
  3245.  
  3246.  
  3247. /*
  3248.  * This is only used at startup time.  It sets ps->def_sort and
  3249.  * ps->def_sort_rev.  The syntax of the sort_spec is type[/reverse].
  3250.  * A reverse without a type is the same as arrival/reverse.  A blank
  3251.  * argument also means arrival/reverse.
  3252.  */
  3253. int
  3254. decode_sort(ps, sort_spec)
  3255.      struct pine *ps;
  3256.      char        *sort_spec;
  3257. {
  3258.     char *sep;
  3259.     int    x, reverse;
  3260.  
  3261.     if(*sort_spec == '\0' ||
  3262.            struncmp(sort_spec, "reverse", strlen(sort_spec)) == 0){
  3263.     ps->def_sort_rev = 1;
  3264.         return(0);
  3265.     }
  3266.      
  3267.     reverse = 0;
  3268.     if((sep = strindex(sort_spec, '/')) != NULL){
  3269.         *sep = '\0';
  3270.         sep++;
  3271.         if(struncmp(sep, "reverse", strlen(sep)) == 0)
  3272.           reverse = 1;
  3273.         else
  3274.           return(-1);
  3275.     }
  3276.  
  3277.     for(x = 0; ps_global->sort_types[x] != EndofList; x++)
  3278.       if(struncmp(sort_name(ps_global->sort_types[x]),
  3279.                   sort_spec, strlen(sort_spec)) == 0)
  3280.         break;
  3281.  
  3282.     if(ps_global->sort_types[x] == EndofList)
  3283.       return(-1);
  3284.  
  3285.     ps->def_sort     = ps_global->sort_types[x];
  3286.     ps->def_sort_rev = reverse;
  3287.     return(0);
  3288. }
  3289.  
  3290.  
  3291. /*------------------------------------------------------------
  3292.     Dump out a global pine.conf on the standard output with fresh
  3293.     comments.  Preserves variables currently set in SYSTEM_PINERC, if any.
  3294.   ----*/
  3295. void
  3296. dump_global_conf()
  3297. {
  3298.      FILE            *f;
  3299.      struct variable *var;
  3300.  
  3301.      read_pinerc(SYSTEM_PINERC, variables, ParseGlobal);
  3302.  
  3303.      f = stdout;
  3304.      if(f == NULL) 
  3305.        goto io_err;
  3306.  
  3307.      fprintf(f, "#      %s -- system wide pine configuration\n#\n",
  3308.          SYSTEM_PINERC);
  3309.      fprintf(f, "# Values here affect all pine users unless they've overidden the values\n");
  3310.      fprintf(f, "# in their .pinerc files.  A copy of this file with current comments may\n");
  3311.      fprintf(f, "# be obtained by running \"pine -conf\". It will be printed to standard output.\n#\n");
  3312.      fprintf(f,"# For a variable to be unset its value must be null/blank.  This is not the\n");
  3313.      fprintf(f,"# same as the value of \"empty string\", which can be used to effectively\n");
  3314.      fprintf(f,"# \"unset\" a variable that has a default or previously assigned value.\n");
  3315.      fprintf(f,"# To set a variable to the empty string its value should be \"\".\n");
  3316.      fprintf(f,"# Switch variables are set to either \"yes\" or \"no\", and default to \"no\".\n");
  3317.      fprintf(f,"# Except for feature-list items, which are additive, values set in the\n");
  3318.      fprintf(f,"# .pinerc file replace those in pine.conf, and those in pine.conf.fixed\n");
  3319.      fprintf(f,"# over-ride all others.  Features can be over-ridden in .pinerc or\n");
  3320.      fprintf(f,"# pine.conf.fixed by pre-pending the feature name with \"no-\".\n#\n");
  3321.      fprintf(f,"# (These comments are automatically inserted.)\n");
  3322.  
  3323.      for(var = variables; var->name != NULL; var++){
  3324.          dprint(5,(debugfile,"write_pinerc: %s = %s\n", var->name,
  3325.                    var->user_val.p ? var->user_val.p : "<not set>"));
  3326.          if(!var->is_global || !var->is_used || var->is_obsolete)
  3327.            continue;
  3328.  
  3329.          if(var->descrip && *var->descrip){
  3330.            if(fprintf(f, "\n# %s\n", var->descrip) == EOF)
  3331.              goto io_err;
  3332.      }
  3333.  
  3334.      if(var->is_list){
  3335.          if(var->global_val.l == NULL){
  3336.          if(fprintf(f, "%s=\n", var->name) == EOF)
  3337.            goto io_err;
  3338.          }else{
  3339.          int i;
  3340.  
  3341.          for(i=0; var->global_val.l[i]; i++)
  3342.            if(fprintf(f, "%s%s%s%s\n", (i) ? "\t" : var->name,
  3343.                   (i) ? "" : "=", var->global_val.l[i],
  3344.                   var->global_val.l[i+1] ? ",":"") == EOF)
  3345.              goto io_err;
  3346.          }
  3347.      }else{
  3348.          if(var->global_val.p == NULL){
  3349.          if(fprintf(f, "%s=\n", var->name) == EOF)
  3350.            goto io_err;
  3351.          }else if(strlen(var->global_val.p) == 0){
  3352.          if(fprintf(f, "%s=\"\"\n", var->name) == EOF)
  3353.                goto io_err;
  3354.          }else{
  3355.          if(fprintf(f,"%s=%s\n",var->name,var->global_val.p) == EOF)
  3356.            goto io_err;
  3357.          }
  3358.      }
  3359.      }
  3360.      exit(0);
  3361.  
  3362.  
  3363.    io_err:
  3364.      fprintf(stderr, "Error writing config to stdout: %s\n",
  3365.              error_description(errno));
  3366.      exit(-1);
  3367. }
  3368.  
  3369.  
  3370. /*------------------------------------------------------------
  3371.     Dump out a pinerc to filename with fresh
  3372.     comments.  Preserves variables currently set in pinerc, if any.
  3373.   ----*/
  3374. void
  3375. dump_new_pinerc(filename)
  3376. char *filename;
  3377. {
  3378.     FILE            *f;
  3379.     struct variable *var;
  3380.     char             buf[MAXPATH];
  3381.  
  3382. #if defined(DOS) || defined(OS2)
  3383.     if(!ps_global->pinerc){
  3384.     char *p;
  3385.     int   l;
  3386.  
  3387.     if(p = getenv("PINERC")){
  3388.         ps_global->pinerc = cpystr(p);
  3389.     }else{
  3390.         char buf2[MAXPATH];
  3391.         build_path(buf2, ps_global->home_dir, DF_PINEDIR);
  3392.         build_path(buf, buf2, SYSTEM_PINERC);
  3393.     }
  3394.     }
  3395. #else    /* !DOS */
  3396.     if(!ps_global->pinerc)
  3397.     build_path(buf, ps_global->home_dir, ".pinerc");
  3398. #endif    /* !DOS */
  3399.  
  3400.     read_pinerc(buf, variables, ParseLocal);
  3401.  
  3402.     f = NULL;;
  3403.     if(filename[0] == '\0'){
  3404.     fprintf(stderr, "Missing argument to \"-pinerc\".\n");
  3405.     }else if(!strcmp(filename, "-")){
  3406.     f = stdout;
  3407.     }else{
  3408.     f = fopen(filename, "w");
  3409.     }
  3410.  
  3411.     if(f == NULL) 
  3412.     goto io_err;
  3413.  
  3414.     if(fprintf(f, "%s%s%s", cf_text_comment1, pine_version,
  3415.            cf_text_comment2) == EOF)
  3416.     goto io_err;
  3417.     if(fprintf(f, "%s", cf_text_comment3) == EOF)
  3418.     goto io_err;
  3419.  
  3420.     for(var = variables; var->name != NULL; var++){
  3421.     dprint(5,(debugfile,"write_pinerc: %s = %s\n", var->name,
  3422.                    var->user_val.p ? var->user_val.p : "<not set>"));
  3423.         if(!var->is_user || !var->is_used || var->is_obsolete)
  3424.         continue;
  3425.  
  3426.     /* Add extra comments about categories of variables */
  3427.         if(var == &variables[V_PERSONAL_NAME]){
  3428.         if(fprintf(f, "\n%s\n", cf_before_personal_name) == EOF)
  3429.         goto io_err;
  3430.         }else if(var == &variables[V_INCOMING_FOLDERS]){
  3431.         if(fprintf(f, "\n%s\n", cf_before_incoming_folders) == EOF)
  3432.         goto io_err;
  3433.         }else if(var == &variables[V_FEATURE_LIST]){
  3434.         if(fprintf(f, "\n%s\n", cf_before_feature_list) == EOF)
  3435.         goto io_err;
  3436.         }else if(var == &variables[V_PRINTER]){
  3437.         if(fprintf(f, "\n%s\n", cf_before_printer) == EOF)
  3438.         goto io_err;
  3439.         }
  3440.  
  3441.     /*
  3442.      * set description to NULL to eliminate preceding
  3443.      * blank and comment line.
  3444.      */
  3445.          if(var->descrip && *var->descrip){
  3446.            if(fprintf(f, "\n# %s\n", var->descrip) == EOF)
  3447.              goto io_err;
  3448.      }
  3449.  
  3450.     if(var->is_list){
  3451.         if(var->user_val.l == NULL){
  3452.         if(fprintf(f, "%s=\n", var->name) == EOF)
  3453.             goto io_err;
  3454.         }else{
  3455.         int i;
  3456.  
  3457.         for(i=0; var->user_val.l[i]; i++)
  3458.             if(fprintf(f, "%s%s%s%s\n", (i) ? "\t" : var->name,
  3459.                   (i) ? "" : "=", var->user_val.l[i],
  3460.                   var->user_val.l[i+1] ? ",":"") == EOF)
  3461.             goto io_err;
  3462.         }
  3463.     }else{
  3464.         if(var->user_val.p == NULL){
  3465.         if(fprintf(f, "%s=\n", var->name) == EOF)
  3466.             goto io_err;
  3467.         }else if(strlen(var->user_val.p) == 0){
  3468.         if(fprintf(f, "%s=\"\"\n", var->name) == EOF)
  3469.             goto io_err;
  3470.         }else{
  3471.         if(fprintf(f,"%s=%s\n",var->name,var->user_val.p) == EOF)
  3472.             goto io_err;
  3473.         }
  3474.     }
  3475.     }
  3476.     exit(0);
  3477.  
  3478.  
  3479. io_err:
  3480.     fprintf(stderr, "Error writing config to %s: %s\n",
  3481.              filename, error_description(errno));
  3482.     exit(-1);
  3483. }
  3484.  
  3485.  
  3486. /*----------------------------------------------------------------------
  3487.   Dump the whole config enchilada using the given function
  3488.    
  3489.   Args: ps -- pine struct containing vars to dump
  3490.     pc -- function to use to write the config data
  3491.  
  3492.  Result: command line, global, user var's written with given function
  3493.  
  3494.  ----*/ 
  3495. void
  3496. dump_config(ps, pc)
  3497.     struct pine *ps;
  3498.     gf_io_t pc;
  3499. {
  3500.     int           i;
  3501.     char       quotes[3], tmp[MAILTMPLEN];
  3502.     register struct variable *vars;
  3503.     NAMEVAL_S *feat;
  3504.  
  3505.     quotes[0] = '"'; quotes[1] = '"'; quotes[2] = '\0';
  3506.  
  3507.     for(i=0; i < 5; i++){
  3508.     sprintf(tmp, "======= %s_val options set",
  3509.         (i == 0) ? "Current" :
  3510.          (i == 1) ? "Command_line" :
  3511.           (i == 2) ? "User" :
  3512.            (i == 3) ? "Global"
  3513.                 : "Fixed");
  3514.     gf_puts(tmp, pc);
  3515.     if(i > 1){
  3516.         sprintf(tmp, " (%s)",
  3517.             (i == 2) ? ((ps->pinerc) ? ps->pinerc
  3518.                          : ".pinerc") :
  3519.             (i == 3) ? ((ps->pine_conf) ? ps->pine_conf
  3520.                         : SYSTEM_PINERC) :
  3521. #if defined(DOS) || defined(OS2)
  3522.             "NO FIXED"
  3523. #else
  3524.             ((can_access(SYSTEM_PINERC_FIXED, ACCESS_EXISTS) == 0)
  3525.                  ? SYSTEM_PINERC_FIXED : "NO pine.conf.fixed")
  3526. #endif
  3527.             );
  3528.         gf_puts(tmp, pc);
  3529.     }
  3530.  
  3531.     gf_puts(" =======\n", pc);
  3532.     for(vars = ps->vars; vars->name; vars++){
  3533.         if(vars->is_list){
  3534.         char **t;
  3535.         t = (i == 0) ? vars->current_val.l :
  3536.              (i == 1) ? vars->cmdline_val.l :
  3537.               (i == 2) ? vars->user_val.l :
  3538.             (i == 3) ? vars->global_val.l
  3539.                  : vars->fixed_val.l;
  3540.         if(t && *t){
  3541.             sprintf(tmp, " %20.20s : %s\n", vars->name,
  3542.                 **t ? *t : quotes);
  3543.             gf_puts(tmp, pc);
  3544.             while(++t && *t){
  3545.             sprintf(tmp," %20.20s : %s\n","",**t ? *t : quotes);
  3546.             gf_puts(tmp, pc);
  3547.             }
  3548.         }
  3549.         }
  3550.         else{
  3551.         char *t;
  3552.         t = (i == 0) ? vars->current_val.p :
  3553.              (i == 1) ? vars->cmdline_val.p :
  3554.               (i == 2) ? vars->user_val.p :
  3555.                (i == 3) ? vars->global_val.p
  3556.                 : vars->fixed_val.p;
  3557.         if(t){
  3558.             sprintf(tmp, " %20.20s : %s\n", vars->name,
  3559.                 *t ? t : quotes);
  3560.             gf_puts(tmp, pc);
  3561.         }
  3562.         }
  3563.     }
  3564.     }
  3565.  
  3566.     gf_puts("========== Feature settings ==========\n", pc);
  3567.     for(i = 0; feat = feature_list(i) ; i++)
  3568.       if(feat->value != F_OLD_GROWTH){
  3569.       sprintf(tmp, "  %s%s\n", F_ON(feat->value,ps) ? "   " : "no-",
  3570.           feat->name);
  3571.       gf_puts(tmp, pc);
  3572.       }
  3573. }
  3574.  
  3575.  
  3576. /*----------------------------------------------------------------------
  3577.   Dump interesting variables from the given pine struct
  3578.    
  3579.   Args: ps -- pine struct to dump 
  3580.     pc -- function to use to write the config data
  3581.  
  3582.  Result: various important pine struct data written
  3583.  
  3584.  ----*/ 
  3585. void
  3586. dump_pine_struct(ps, pc)
  3587.     struct pine *ps;
  3588.     gf_io_t pc;
  3589. {
  3590.     char *p;
  3591.     extern char term_name[];
  3592.  
  3593.     gf_puts("========== struct pine * ==========\n", pc);
  3594.     if(!ps){
  3595.     gf_puts("!No struct!\n", pc);
  3596.     return;
  3597.     }
  3598.  
  3599.     gf_puts("ui:\tlogin = ", pc);
  3600.     gf_puts((ps->ui.login) ? ps->ui.login : "NULL", pc);
  3601.     gf_puts(", full = ", pc);
  3602.     gf_puts((ps->ui.fullname) ? ps->ui.fullname : "NULL", pc);
  3603.     gf_puts("\n\thome = ", pc);
  3604.     gf_puts((ps->ui.homedir) ? ps->ui.homedir : "NULL", pc);
  3605.  
  3606.     gf_puts("\nhome_dir=\t", pc);
  3607.     gf_puts(ps->home_dir ? ps->home_dir : "NULL", pc);
  3608.     gf_puts("\nhostname=\t", pc);
  3609.     gf_puts(ps->hostname ? ps->hostname : "NULL", pc);
  3610.     gf_puts("\nlocaldom=\t", pc);
  3611.     gf_puts(ps->localdomain ? ps->localdomain : "NULL", pc);
  3612.     gf_puts("\nuserdom=\t", pc);
  3613.     gf_puts(ps->userdomain ? ps->userdomain : "NULL", pc);
  3614.     gf_puts("\nmaildom=\t", pc);
  3615.     gf_puts(ps->maildomain ? ps->maildomain : "NULL", pc);
  3616.  
  3617.     if(ps->mail_stream){
  3618.     gf_puts("\ncur_cntxt=\t", pc);
  3619.     gf_puts((ps->context_current && ps->context_current->context)
  3620.         ? ps->context_current->context : "None", pc);
  3621.     gf_puts("\ncur_fldr=\t", pc);
  3622.     gf_puts(ps->cur_folder, pc);
  3623.     gf_puts("\nactual mbox=\t", pc);
  3624.     gf_puts(ps->mail_stream->mailbox ? ps->mail_stream->mailbox
  3625.                      : "no mailbox!", pc);
  3626.     if(ps->msgmap){
  3627.         gf_puts("\nmsgmap: tot=", pc);
  3628.         gf_puts(long2string(mn_get_total(ps->msgmap)), pc);
  3629.         gf_puts(", cur=", pc);
  3630.         gf_puts(long2string(mn_get_cur(ps->msgmap)), pc);
  3631.         gf_puts(", del=", pc);
  3632.         gf_puts(long2string(count_flagged(ps->mail_stream, "DELETED")),pc);
  3633.         gf_puts(", hid=", pc);
  3634.         gf_puts(long2string(any_lflagged(ps->msgmap, MN_HIDE)), pc);
  3635.         gf_puts(", exld=", pc);
  3636.         gf_puts(long2string(any_lflagged(ps->msgmap, MN_EXLD)), pc);
  3637.         gf_puts(", slct=", pc);
  3638.         gf_puts(long2string(any_lflagged(ps->msgmap, MN_SLCT)), pc);
  3639.         gf_puts(", sort=", pc);
  3640.         if(mn_get_revsort(ps->msgmap))
  3641.           gf_puts("rev-", pc);
  3642.  
  3643.         gf_puts(sort_name(mn_get_sort(ps->msgmap)), pc);
  3644.     }
  3645.     else
  3646.       gf_puts("\nNo msgmap", pc);
  3647.     }
  3648.     else
  3649.       gf_puts("\nNo mail_stream", pc);
  3650.  
  3651.     if(ps->inbox_stream && (ps->mail_stream != ps->inbox_stream)){
  3652.     gf_puts("\nactual inbox=\t", pc);
  3653.     gf_puts(ps->inbox_stream->mailbox ? ps->inbox_stream->mailbox
  3654.                       : "no mailbox!", pc);
  3655.     if(ps->inbox_msgmap){
  3656.         gf_puts("\ninbox map: tot=", pc);
  3657.         gf_puts(long2string(mn_get_total(ps->inbox_msgmap)), pc);
  3658.         gf_puts(", cur=", pc);
  3659.         gf_puts(long2string(mn_get_cur(ps->inbox_msgmap)), pc);
  3660.         gf_puts(", del=", pc);
  3661.         gf_puts(long2string(count_flagged(ps->inbox_stream,"DELETED")),pc);
  3662.         gf_puts(", hid=", pc);
  3663.         gf_puts(long2string(any_lflagged(ps->inbox_msgmap, MN_HIDE)), pc);
  3664.         gf_puts(", exld=", pc);
  3665.         gf_puts(long2string(any_lflagged(ps->inbox_msgmap, MN_EXLD)), pc);
  3666.         gf_puts(", slct=", pc);
  3667.         gf_puts(long2string(any_lflagged(ps->inbox_msgmap, MN_SLCT)), pc);
  3668.         gf_puts(", sort=", pc);
  3669.         if(mn_get_revsort(ps->inbox_msgmap))
  3670.           gf_puts("rev-", pc);
  3671.  
  3672.         gf_puts(sort_name(mn_get_sort(ps->inbox_msgmap)), pc);
  3673.     }
  3674.     else
  3675.       gf_puts("\nNo inbox_map", pc);
  3676.     }
  3677.     else
  3678.       gf_puts(ps->inbox_stream ? "\ninbox is mail_stream"
  3679.                    : "\nno inbox stream", pc);
  3680.     gf_puts("\nterm ", pc);
  3681. #if !defined(DOS) && !defined(OS2)
  3682.     gf_puts("type=", pc);
  3683.     gf_puts(term_name, pc);
  3684.     gf_puts(", ttyname=", pc);
  3685.     gf_puts((p = (char *)ttyname(0)) ? p : "NONE", pc);
  3686. #endif
  3687.     gf_puts(", size=", pc);
  3688.     gf_puts(int2string(ps->ttyo->screen_rows), pc);
  3689.     gf_puts("x", pc);
  3690.     gf_puts(int2string(ps->ttyo->screen_cols), pc);
  3691.     gf_puts(", speed=", pc);
  3692.     gf_puts((ps->low_speed) ? "slow" : "normal", pc);
  3693.     gf_puts("\n", pc);
  3694. }
  3695.  
  3696.  
  3697. /*----------------------------------------------------------------------
  3698.       Set a user variable and save the .pinerc
  3699.    
  3700.   Args:  var -- The index of the variable to set from pine.h (V_....)
  3701.          value -- The string to set the value to
  3702.  
  3703.  Result: -1 is returned on failure and 0 is returned on success
  3704.  
  3705.  The vars data structure is updated and the pinerc saved.
  3706.  ----*/ 
  3707. set_variable(var, value, commit)
  3708.      int   var, commit;
  3709.      char *value;
  3710. {
  3711.     struct variable *v;
  3712.  
  3713.     v = &ps_global->vars[var];
  3714.  
  3715.     if(!v->is_user) 
  3716.       panic1("Trying to set non-user variable %s", v->name);
  3717.  
  3718.     if(v->user_val.p)
  3719.       fs_give((void **) &v->user_val.p);
  3720.  
  3721.     if(v->current_val.p)
  3722.       fs_give((void **) &v->current_val.p);
  3723.  
  3724.     v->user_val.p    = value ? cpystr(value) : NULL;
  3725.     v->current_val.p = value ? cpystr(value) : NULL;
  3726.  
  3727.     ps_global->outstanding_pinerc_changes = 1;
  3728.  
  3729.     return(commit ? write_pinerc(ps_global) : 1);
  3730. }
  3731.  
  3732.  
  3733. /*----------------------------------------------------------------------
  3734.       Set a user variable list and save the .pinerc
  3735.    
  3736.   Args:  var -- The index of the variable to set from pine.h (V_....)
  3737.          lvalue -- The list to set the value to
  3738.  
  3739.  Result: -1 is returned on failure and 0 is returned on success
  3740.  
  3741.  The vars data structure is updated and the pinerc saved.
  3742.  ----*/ 
  3743. set_variable_list(var, lvalue)
  3744.     int    var;
  3745.     char **lvalue;
  3746. {
  3747.     int              i;
  3748.     struct variable *v = &ps_global->vars[var];
  3749.  
  3750.     if(!v->is_user || !v->is_list)
  3751.       panic1("BOTCH: Trying to set non-user or non-list variable %s", v->name);
  3752.  
  3753.     if(v->user_val.l){
  3754.     for(i = 0; v->user_val.l[i] ; i++)
  3755.       fs_give((void **) &v->user_val.l[i]);
  3756.  
  3757.     fs_give((void **) &v->user_val.l);
  3758.     }
  3759.  
  3760.     if(v->current_val.l){
  3761.     for(i = 0; v->current_val.l[i] ; i++)
  3762.       fs_give((void **) &v->current_val.l[i]);
  3763.  
  3764.     fs_give((void **) &v->current_val.l);
  3765.     }
  3766.  
  3767. /* BUG: HAVING MULTIPLE COPIES OF CONFIG DATA IS BOGUS */
  3768.     if(lvalue){
  3769.     for(i = 0; lvalue[i] ; i++)    /* count elements */
  3770.       ;
  3771.  
  3772.     v->user_val.l    = (char **) fs_get((i+1) * sizeof(char *));
  3773.     v->current_val.l = (char **) fs_get((i+1) * sizeof(char *));
  3774.  
  3775.     for(i = 0; lvalue[i] ; i++){
  3776.         v->user_val.l[i]    = cpystr(lvalue[i]);
  3777.         v->current_val.l[i] = cpystr(lvalue[i]);
  3778.     }
  3779.  
  3780.     v->user_val.l[i]    = NULL;
  3781.     v->current_val.l[i] = NULL;
  3782.     }
  3783.  
  3784.  
  3785.     return(write_pinerc(ps_global));
  3786. }
  3787.            
  3788.  
  3789. /*----------------------------------------------------------------------
  3790.     Make sure the pine folders directory exists, with proper folders
  3791.  
  3792.    Args: ps -- pine structure to get mail directory and contexts from
  3793.  
  3794.   Result: returns 0 if it exists or it is created and all is well
  3795.                   1 if it is missing and can't be created.
  3796.   ----*/
  3797. init_mail_dir(ps)
  3798.     struct pine *ps;
  3799. {
  3800.     /*
  3801.      * We don't really care if mail_dir exists if it isn't 
  3802.      * part of the first folder collection specified.  If this
  3803.      * is the case, it must have been created external to us, so
  3804.      * just move one...
  3805.      */
  3806.     if(ps->VAR_FOLDER_SPEC && ps->VAR_FOLDER_SPEC[0]){
  3807.     char *p  = context_string(ps->VAR_FOLDER_SPEC[0]);
  3808.     int   rv = strncmp(p, ps->VAR_MAIL_DIRECTORY,
  3809.                strlen(ps->VAR_MAIL_DIRECTORY));
  3810.     fs_give((void **)&p);
  3811.     if(rv)
  3812.       return(0);
  3813.     }
  3814.  
  3815.     switch(is_writable_dir(ps->folders_dir)){
  3816.       case 0:
  3817.         /* --- all is well --- */
  3818.         return(0);
  3819.  
  3820.       case 1:
  3821.         printf("The \"mail\" subdirectory already exists, but it is");
  3822.         printf(" not writable by pine\nso pine cannot run. Please correct");
  3823.        printf(" the permissions and restart pine.\n");
  3824.         return(-1);
  3825.  
  3826.       case 2:
  3827.         printf("Pine requires a directory called \"mail\" and usualy ");
  3828.        printf("creates it.\nYou already have a regular file called ");
  3829.     printf("\"mail\" which is in the way.\nPlease move or remove ");
  3830.     printf("\"mail\" and start pine again.\n");
  3831.         return(-1);
  3832.  
  3833.       case 3:
  3834.         printf("Creating subdirectory \"%s\" where pine", ps->folders_dir);
  3835.     printf(" will store\nits mail folders.\n");
  3836.         sleep(4);
  3837.         if(create_mail_dir(ps->folders_dir) < 0){
  3838.             printf("%cError creating subdirectory \"%s\" : %s\n",
  3839.            BELL, ps->folders_dir, error_description(errno));
  3840.             return(-1);
  3841.         }
  3842.     }
  3843.  
  3844.     return(0);
  3845. }
  3846.  
  3847.  
  3848. /*----------------------------------------------------------------------
  3849.   Make sure the default save folders exist in the default
  3850.   save context.
  3851.   ----*/
  3852. void
  3853. init_save_defaults()
  3854. {
  3855.     CONTEXT_S  *save_cntxt;
  3856.  
  3857.     if(!ps_global->VAR_DEFAULT_FCC || !*ps_global->VAR_DEFAULT_FCC)
  3858.       return;
  3859.  
  3860.     if(!(save_cntxt = default_save_context(ps_global->context_list)))
  3861.       save_cntxt = ps_global->context_list;
  3862.  
  3863.     if(context_isambig(ps_global->VAR_DEFAULT_FCC)){
  3864.     find_folders_in_context(NULL, save_cntxt, ps_global->VAR_DEFAULT_FCC);
  3865.     if(folder_index(ps_global->VAR_DEFAULT_FCC, save_cntxt->folders) < 0)
  3866.       context_create(save_cntxt->context, NULL,
  3867.              ps_global->VAR_DEFAULT_FCC);
  3868.     }
  3869.  
  3870.     find_folders_in_context(NULL, save_cntxt,
  3871.                 ps_global->VAR_DEFAULT_SAVE_FOLDER);
  3872.     if(folder_index(ps_global->VAR_DEFAULT_SAVE_FOLDER,
  3873.             save_cntxt->folders) < 0)
  3874.       context_create(save_cntxt->context, NULL,
  3875.              ps_global->VAR_DEFAULT_SAVE_FOLDER);
  3876.  
  3877.     free_folders_in_context(save_cntxt);
  3878. }
  3879.  
  3880.  
  3881.  
  3882. /*----------------------------------------------------------------------
  3883.    Routines for pruning old Fcc, usually "sent-mail" folders.     
  3884.   ----*/
  3885. struct sm_folder {
  3886.     char *name;
  3887.     int   month_num;
  3888. };
  3889.  
  3890.  
  3891. /*
  3892.  * Pruning prototypes
  3893.  */
  3894. void     delete_old_mail PROTO((struct sm_folder *, CONTEXT_S *, char *));
  3895. struct     sm_folder *get_mail_list PROTO((CONTEXT_S *, char *));
  3896. int     prune_folders PROTO((CONTEXT_S *, char *, int, char *));
  3897.  
  3898.  
  3899.  
  3900. /*----------------------------------------------------------------------
  3901.       Put sent-mail files in date order 
  3902.  
  3903.    Args: a, b  -- The names of two files.  Expects names to be sent-mail-mmm-yy
  3904.                   Other names will sort in order and come before those
  3905.                   in above format.
  3906.  ----*/
  3907. int   
  3908. compare_sm_files(aa, bb)
  3909.     const QSType *aa, *bb;
  3910. {
  3911.     struct sm_folder *a = (struct sm_folder *)aa,
  3912.                      *b = (struct sm_folder *)bb;
  3913.  
  3914.     if(a->month_num == -1 && b->month_num == -1)
  3915.       return(strucmp(a->name, b->name));
  3916.     if(a->month_num == -1)      return(-1);
  3917.     if(b->month_num == -1)      return(1);
  3918.  
  3919.     return(a->month_num - b->month_num);
  3920. }
  3921.  
  3922.  
  3923.  
  3924. /*----------------------------------------------------------------------
  3925.       Create an ordered list of sent-mail folders and their month numbers
  3926.  
  3927.    Args: dir -- The directory to find the list of files in
  3928.  
  3929.  Result: Pointer to list of files is returned. 
  3930.  
  3931. This list includes all files that start with "sent-mail", but not "sent-mail" 
  3932. itself.
  3933.   ----*/
  3934. struct sm_folder *
  3935. get_mail_list(list_cntxt, folder_base)
  3936.     CONTEXT_S *list_cntxt;
  3937.     char      *folder_base;
  3938. {
  3939. #define MAX_FILES  (150)
  3940.     register struct sm_folder *sm  = NULL;
  3941.     struct sm_folder          *sml = NULL;
  3942.     char                      *filename;
  3943.     int                        i, folder_base_len;
  3944.     char               searchname[MAXPATH+1];
  3945.  
  3946.     sml = sm = (struct sm_folder *)fs_get(sizeof(struct sm_folder)*MAX_FILES);
  3947.     memset((void *)sml, 0, sizeof(struct sm_folder) * MAX_FILES);
  3948.     if((folder_base_len = strlen(folder_base)) == 0 || !list_cntxt){
  3949.         sml->name = cpystr("");
  3950.         return(sml);
  3951.     }
  3952.  
  3953. #ifdef    DOS
  3954.     if(*list_cntxt->context != '{'){    /* NOT an IMAP collection! */
  3955.     sprintf(searchname, "%4.4s*", folder_base);
  3956.     folder_base_len = strlen(searchname) - 1;
  3957.     }
  3958.     else
  3959. #endif
  3960.     sprintf(searchname, "%s*", folder_base);
  3961.  
  3962.     find_folders_in_context(NULL, list_cntxt, searchname);
  3963.     for(i = 0; i < folder_total(list_cntxt->folders); i++){
  3964.     filename = folder_entry(i, list_cntxt->folders)->name;
  3965. #ifdef    DOS
  3966.         if(struncmp(filename, folder_base, folder_base_len) == 0
  3967.            && strucmp(filename, folder_base)){
  3968.  
  3969.     if(*list_cntxt->context != '{'){
  3970.         int j;
  3971.         for(j = 0; j < 4; j++)
  3972.           if(!isdigit(filename[folder_base_len + j]))
  3973.         break;
  3974.  
  3975.        if(j < 4)        /* not proper date format! */
  3976.          continue;        /* keep trying */
  3977.     }
  3978. #else
  3979. #ifdef OS2
  3980.         if(strnicmp(filename, folder_base, folder_base_len) == 0
  3981.            && stricmp(filename, folder_base)){
  3982. #else
  3983.         if(strncmp(filename, folder_base, folder_base_len) == 0
  3984.            && strcmp(filename, folder_base)){
  3985. #endif
  3986. #endif
  3987.         sm->name = cpystr(filename);
  3988. #ifdef    DOS
  3989.         if(*list_cntxt->context != '{'){ /* NOT an IMAP collection! */
  3990.         sm->month_num  = (sm->name[folder_base_len] - '0') * 10;
  3991.         sm->month_num += sm->name[folder_base_len + 1] - '0';
  3992.         }
  3993.         else
  3994. #endif
  3995.             sm->month_num = month_num(sm->name + (size_t)folder_base_len + 1);
  3996.             sm++;
  3997.             if(sm >= &sml[MAX_FILES])
  3998.                break; /* Too many files, ignore the rest ; shouldn't occur */
  3999.         }
  4000.     }
  4001.  
  4002.     sm->name = cpystr("");
  4003.  
  4004.     /* anything to sort?? */
  4005.     if(sml->name && *(sml->name) && (sml+1)->name && *((sml+1)->name)){
  4006.     qsort(sml,
  4007.           sm - sml,
  4008.           sizeof(struct sm_folder),
  4009.           compare_sm_files);
  4010.     }
  4011.  
  4012.     return(sml);
  4013. }
  4014.  
  4015.  
  4016.  
  4017. /*----------------------------------------------------------------------
  4018.       Rename the current sent-mail folder to sent-mail for last month
  4019.  
  4020.    open up sent-mail and get date of very first message
  4021.    if date is last month rename and...
  4022.        if files from 3 months ago exist ask if they should be deleted and...
  4023.            if files from previous months and yes ask about them, too.   
  4024.   ----------------------------------------------------------------------*/
  4025. int
  4026. expire_sent_mail()
  4027. {
  4028.     int         cur_month, ok = 1;
  4029.     time_t     now;
  4030.     char     tmp[20], **p;
  4031.     struct tm    *tm_now;
  4032.     CONTEXT_S    *prune_cntxt;
  4033.  
  4034.     dprint(5, (debugfile, "==== expire_mail called ====\n"));
  4035.  
  4036.     now = time((time_t *)0);
  4037.     tm_now = localtime(&now);
  4038.  
  4039.     /*
  4040.      * If the last time we did this is blank (as if pine's run for
  4041.      * first time), don't go thru list asking, but just note it for 
  4042.      * the next time...
  4043.      */
  4044.     if(ps_global->VAR_LAST_TIME_PRUNE_QUESTION == NULL){
  4045.     ps_global->last_expire_year = tm_now->tm_year;
  4046.     ps_global->last_expire_month = tm_now->tm_mon;
  4047.     sprintf(tmp, "%d.%d", ps_global->last_expire_year,
  4048.         ps_global->last_expire_month + 1);
  4049.     set_variable(V_LAST_TIME_PRUNE_QUESTION, tmp, 1);
  4050.     return(0);
  4051.     }
  4052.  
  4053.     if(ps_global->last_expire_year != -1 &&
  4054.       (tm_now->tm_year <  ps_global->last_expire_year ||
  4055.        (tm_now->tm_year == ps_global->last_expire_year &&
  4056.         tm_now->tm_mon <= ps_global->last_expire_month)))
  4057.       return(0); 
  4058.     
  4059.     cur_month = (1900 + tm_now->tm_year) * 12 + tm_now->tm_mon;
  4060.     dprint(5, (debugfile, "Current month %d\n", cur_month));
  4061.  
  4062.     /*
  4063.      * locate the default save context...
  4064.      */
  4065.     if(!(prune_cntxt = default_save_context(ps_global->context_list)))
  4066.       prune_cntxt = ps_global->context_list;
  4067.  
  4068.     /*
  4069.      * Since fcc's and read-mail can be an IMAP mailbox, be sure to only
  4070.      * try expiring a list if it's an ambiguous name associated with some
  4071.      * collection...
  4072.      *
  4073.      * If sentmail set outside a context, then pruning is up to the
  4074.      * user...
  4075.      */
  4076.     if(prune_cntxt){
  4077.     if(ps_global->VAR_DEFAULT_FCC && *ps_global->VAR_DEFAULT_FCC
  4078.        && context_isambig(ps_global->VAR_DEFAULT_FCC))
  4079.       ok = prune_folders(prune_cntxt, ps_global->VAR_DEFAULT_FCC,
  4080.                  cur_month, "SENT");
  4081.  
  4082.     if(ok && ps_global->VAR_READ_MESSAGE_FOLDER 
  4083.        && *ps_global->VAR_READ_MESSAGE_FOLDER
  4084.        && context_isambig(ps_global->VAR_READ_MESSAGE_FOLDER))
  4085.       ok = prune_folders(prune_cntxt, ps_global->VAR_READ_MESSAGE_FOLDER,
  4086.                  cur_month, "READ");
  4087.     }
  4088.  
  4089.     /*
  4090.      * Within the default prune context,
  4091.      * prune back the folders with the given name
  4092.      */
  4093.     if(ok && prune_cntxt && (p = ps_global->VAR_PRUNED_FOLDERS))
  4094.       for(; ok && *p; p++)
  4095.     if(**p && context_isambig(*p))
  4096.       ok = prune_folders(prune_cntxt, *p, cur_month, "");
  4097.  
  4098.     /*
  4099.      * Mark that we're done for this month...
  4100.      */
  4101.     if(ok){
  4102.     ps_global->last_expire_year = tm_now->tm_year;
  4103.     ps_global->last_expire_month = tm_now->tm_mon;
  4104.     sprintf(tmp, "%d.%d", ps_global->last_expire_year,
  4105.         ps_global->last_expire_month + 1);
  4106.     set_variable(V_LAST_TIME_PRUNE_QUESTION, tmp, 1);
  4107.     }
  4108.  
  4109.     return(1);
  4110. }
  4111.  
  4112.  
  4113.  
  4114. /*----------------------------------------------------------------------
  4115.      Offer to delete old sent-mail folders
  4116.  
  4117.   Args: sml -- The list of sent-mail folders
  4118.  
  4119.   ----*/
  4120. int
  4121. prune_folders(prune_cntxt, folder_base, cur_month, type)
  4122.     CONTEXT_S *prune_cntxt;
  4123.     char      *folder_base, *type;
  4124.     int        cur_month;
  4125. {
  4126.     char         path[MAXPATH+1], path2[MAXPATH+1],  prompt[128], tmp[20];
  4127.     int          month_to_use, i;
  4128.     MAILSTREAM  *prune_stream;
  4129.     struct sm_folder *mail_list, *sm;
  4130.  
  4131.     mail_list = get_mail_list(prune_cntxt, folder_base);
  4132.  
  4133. #ifdef    DEBUG
  4134.     for(sm = mail_list; sm != NULL && sm->name[0] != '\0'; sm++)
  4135.       dprint(5, (debugfile,"Old sent-mail: %5d  %s\n",sm->month_num,sm->name));
  4136. #endif
  4137.  
  4138.     for(sm = mail_list; sm != NULL && sm->name[0] != '\0'; sm++)
  4139.       if(sm->month_num == cur_month - 1)
  4140.         break;  /* matched a month */
  4141.  
  4142.     month_to_use = (sm == NULL || sm->name[0] == '\0') ? cur_month - 1 : 0;
  4143.  
  4144.     dprint(5, (debugfile, "Month_to_use : %d\n", month_to_use));
  4145.  
  4146.     if(month_to_use == 0)
  4147.       goto delete_old;
  4148.  
  4149.     strcpy(path, folder_base);
  4150. /* BUG: how to check that a folder is zero_length via c-client?? */
  4151.     strcpy(path2, folder_base);
  4152.     strcpy(tmp, month_abbrev((month_to_use % 12)+1));
  4153.     lcase(tmp);
  4154. #ifdef    DOS
  4155.     if(*prune_cntxt->context != '{'){
  4156.       sprintf(path2 + (size_t)(((i = strlen(path2)) > 4) ? 4 : i),
  4157.           "%2.2d%2.2d", (month_to_use % 12) + 1,
  4158.           ((month_to_use / 12) - 1900) % 100);
  4159.     }
  4160.     else
  4161. #endif
  4162.     sprintf(path2 + strlen(path2), "-%s-%2d", tmp, month_to_use/12);
  4163.  
  4164.     Writechar(BELL, 0);
  4165.     sprintf(prompt, "Move current \"%s\" to \"%s\"", path, path2);
  4166.     switch(folder_exists(prune_cntxt->context, folder_base)){
  4167.       case -1 :            /* error! */
  4168.         dprint(5, (debugfile, "prune_folders: Error testing existance\n"));
  4169.         return(0);
  4170.  
  4171.       case 0 :            /* doesn't exist */
  4172.         dprint(5, (debugfile, "prune_folders: nothing to prune <%s %s>\n",
  4173.            prune_cntxt->context, folder_base));
  4174.         goto delete_old;
  4175.  
  4176.       default :
  4177.     if(want_to(prompt, 'n', 0, h_wt_expire, 1, 1) == 'n'){
  4178.         dprint(5, (debugfile, "User declines renaming %s\n",
  4179.                ps_global->VAR_DEFAULT_FCC));
  4180.         goto delete_old;
  4181.     }
  4182.     /* else fall thru processing matching folders */
  4183.  
  4184.     break;
  4185.     }
  4186.  
  4187.     /*--- User says OK to rename ---*/
  4188.     dprint(5, (debugfile, "rename \"%s\" to \"%s\"\n", path, path2));
  4189.     prune_stream = context_same_stream(prune_cntxt->context, path2,
  4190.                        ps_global->mail_stream);
  4191.  
  4192.     if(!prune_stream && ps_global->mail_stream != ps_global->inbox_stream)
  4193.       prune_stream = context_same_stream(prune_cntxt->context, path2,
  4194.                      ps_global->inbox_stream);
  4195.  
  4196.     if(!context_rename(prune_cntxt->context, prune_stream, path, path2)){
  4197.         q_status_message2(SM_ORDER | SM_DING, 3, 4,
  4198.               "Error renaming \"%s\": %s",
  4199.                           pretty_fn(folder_base),
  4200.               error_description(errno));
  4201.         dprint(1, (debugfile, "Error renaming %s to %s: %s\n",
  4202.                    path, path2, error_description(errno)));
  4203.         display_message('x');
  4204.         goto delete_old;
  4205.     }
  4206.  
  4207.     context_create(prune_cntxt->context, prune_stream ? prune_stream : NULL,
  4208.            folder_base);
  4209.  
  4210.   delete_old:
  4211.     delete_old_mail(mail_list, prune_cntxt, type);
  4212.     if(sm = mail_list){
  4213.     while(sm->name){
  4214.         fs_give((void **)&(sm->name));
  4215.         sm++;
  4216.     }
  4217.  
  4218.         fs_give((void **)&mail_list);
  4219.     }
  4220.  
  4221.     return(1);
  4222. }
  4223.  
  4224.  
  4225. /*----------------------------------------------------------------------
  4226.      Offer to delete old sent-mail folders
  4227.  
  4228.   Args: sml       -- The list of sent-mail folders
  4229.         fcc_cntxt -- context to delete list of folders in
  4230.         type      -- label indicating type of folders being deleted
  4231.  
  4232.   ----*/
  4233. void
  4234. delete_old_mail(sml, fcc_cntxt, type)
  4235.     struct sm_folder *sml;
  4236.     CONTEXT_S        *fcc_cntxt;
  4237.     char             *type;
  4238. {
  4239.     char  prompt[150];
  4240.     int   rc;
  4241.     struct sm_folder *sm;
  4242.     MAILSTREAM       *del_stream;
  4243.  
  4244.     for(sm = sml; sm != NULL && sm->name[0] != '\0'; sm++){
  4245.         sprintf(prompt,
  4246.            "To save disk space, delete old %.4s mail folder \"%.30s\" ",
  4247.            type, sm->name);
  4248.         if(want_to(prompt, 'n', 0, h_wt_delete_old, 1, 1) == 'y'){
  4249.         del_stream = context_same_stream(fcc_cntxt->context, sm->name,
  4250.                          ps_global->mail_stream);
  4251.  
  4252.         if(!del_stream 
  4253.            && ps_global->mail_stream != ps_global->inbox_stream)
  4254.           del_stream = context_same_stream(fcc_cntxt->context, sm->name,
  4255.                            ps_global->inbox_stream);
  4256.  
  4257.         if(!context_delete(fcc_cntxt->context, del_stream, sm->name)){
  4258.         q_status_message1(SM_ORDER,
  4259.                   3, 3, "Error deleting \"%s\".", sm->name);
  4260.         dprint(1, (debugfile, "Error context_deleting %s in \n",
  4261.                sm->name, fcc_cntxt->context));
  4262.             }
  4263.     }else{
  4264.         /* break; /* skip out of the whole thing when he says no */
  4265.         /* Decided to keep asking anyway */
  4266.         }
  4267.     }
  4268. }
  4269.